/// <summary> /// 增加一条数据 /// </summary> public int Add(TFXK.Model.SiteConfig model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_SiteConfig("); strSql.Append("codeNo,title,description,mata,footer,des1,des2,des3)"); strSql.Append(" values ("); strSql.Append("@codeNo,@title,@description,@mata,@footer,@des1,@des2,@des3)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@codeNo", SqlDbType.VarChar, 50), new SqlParameter("@title", SqlDbType.VarChar, 100), new SqlParameter("@description", SqlDbType.VarChar, 1000), new SqlParameter("@mata", SqlDbType.VarChar, 1000), new SqlParameter("@footer", SqlDbType.Text), new SqlParameter("@des1", SqlDbType.Text), new SqlParameter("@des2", SqlDbType.VarChar, 500), new SqlParameter("@des3", SqlDbType.VarChar, 500) }; parameters[0].Value = model.codeNo; parameters[1].Value = model.title; parameters[2].Value = model.description; parameters[3].Value = model.mata; parameters[4].Value = model.footer; parameters[5].Value = model.des1; parameters[6].Value = model.des2; parameters[7].Value = model.des3; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(TFXK.Model.SiteConfig model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_SiteConfig set "); strSql.Append("codeNo=@codeNo,"); strSql.Append("title=@title,"); strSql.Append("description=@description,"); strSql.Append("mata=@mata,"); strSql.Append("footer=@footer,"); strSql.Append("des1=@des1,"); strSql.Append("des2=@des2,"); strSql.Append("des3=@des3"); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@codeNo", SqlDbType.VarChar, 50), new SqlParameter("@title", SqlDbType.VarChar, 100), new SqlParameter("@description", SqlDbType.VarChar, 1000), new SqlParameter("@mata", SqlDbType.VarChar, 1000), new SqlParameter("@footer", SqlDbType.Text), new SqlParameter("@des1", SqlDbType.Text), new SqlParameter("@des2", SqlDbType.VarChar, 500), new SqlParameter("@des3", SqlDbType.VarChar, 500) }; parameters[0].Value = model.id; parameters[1].Value = model.codeNo; parameters[2].Value = model.title; parameters[3].Value = model.description; parameters[4].Value = model.mata; parameters[5].Value = model.footer; parameters[6].Value = model.des1; parameters[7].Value = model.des2; parameters[8].Value = model.des3; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public TFXK.Model.SiteConfig GetModel(string codeNo) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,codeNo,title,description,mata,footer,des1,des2,des3 from tb_SiteConfig "); strSql.Append(" where codeNo=@codeNo "); SqlParameter[] parameters = { new SqlParameter("@codeNo", SqlDbType.VarChar, 50) }; parameters[0].Value = codeNo; TFXK.Model.SiteConfig model = new TFXK.Model.SiteConfig(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.codeNo = ds.Tables[0].Rows[0]["codeNo"].ToString(); model.title = ds.Tables[0].Rows[0]["title"].ToString(); model.description = ds.Tables[0].Rows[0]["description"].ToString(); model.mata = ds.Tables[0].Rows[0]["mata"].ToString(); model.footer = ds.Tables[0].Rows[0]["footer"].ToString(); model.des1 = ds.Tables[0].Rows[0]["des1"].ToString(); model.des2 = ds.Tables[0].Rows[0]["des2"].ToString(); model.des3 = ds.Tables[0].Rows[0]["des3"].ToString(); return(model); } else { return(null); } }