protected void Button8_Click(object sender, EventArgs e) { if (Button8.Text == "添加") { M_CateDetail temp = new M_CateDetail(); temp.CateDetailName= TextBox1.Text; temp.CateID = Convert.ToInt32(Session["cateid"]); if (B_CateDetail.Add(temp)) { this.Bind(); } } if (Button8.Text == "更新") { Button8.Text = "添加"; M_CateDetail temp = new M_CateDetail(); temp.CateID =Convert.ToInt32( Session["CateID"]); temp.CateDetailName = TextBox1.Text; temp.CateDetailID = Convert.ToInt32(Session["catedetailid"]); B_CateDetail.Update(temp); this.Bind(); } }
public bool Update(M_CateDetail catedetail) { string sqlStr = "UPDATE ZL_CateDetail SET CateDetailName=@CateDetailName where CateDetailID=@CateDetailID"; SqlParameter[] cmdParams = GetParameters(catedetail); int temp=SqlHelper.ExecuteNonQuery(CommandType.Text,sqlStr, cmdParams); if (temp == 1) return true; else return false; }
public bool Add(M_CateDetail catedetail) { string sqlStr = "INSERT INTO ZL_CateDetail(CateDetailName,CateID) VALUES(@CateDetailName,@CateID)"; SqlParameter[] parameter = new SqlParameter[2]; parameter[0] = new SqlParameter("@CateDetailName", SqlDbType.NVarChar, 50); parameter[0].Value = catedetail.CateDetailName; parameter[1]=new SqlParameter("@CateID",SqlDbType.Int); parameter[1].Value=catedetail.CateID; return SqlHelper.ExecuteSql(sqlStr, parameter); }
public M_CateDetail GetcatedetailById(int catedetailid) { M_CateDetail tempCateDetail=new M_CateDetail(); string sqlstr = "select CateDetailid,catedetailname from zl_catedetail where catedetailid=@catedetailid"; SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = new SqlParameter("@catedetailid", DbType.Int32); parameter[0].Value = catedetailid; DataTable dt=SqlHelper.ExecuteTable(CommandType.Text, sqlstr,parameter); if (dt.Rows.Count != 1) return null; else { tempCateDetail.CateDetailName = (dt.Rows[0]["catedetailname"]).ToString(); tempCateDetail.CateDetailID = Convert.ToInt32(dt.Rows[0]["catedetailid"]); } return tempCateDetail; }
public static bool Update(M_CateDetail catedetailInfo) { return catedetail.Update(catedetailInfo); }
public static bool Add(M_CateDetail catedetailInfo) { return catedetail.Add(catedetailInfo); }
private static SqlParameter[] GetParameters(M_CateDetail catedetail) { SqlParameter[] parameter = new SqlParameter[2]; parameter[0] = new SqlParameter("@CateDetailName", SqlDbType.NVarChar,50); parameter[0].Value = catedetail.CateDetailName; parameter[1] = new SqlParameter("@CateDetailID", SqlDbType.Int); parameter[1].Value = catedetail.CateDetailID; return parameter; }