public bool Update(M_Cate cate) { string sqlStr = "UPDATE ZL_Cate SET [email protected] where [email protected]"; SqlParameter[] cmdParams = GetParameters(cate); return SqlHelper.ExecuteSql(sqlStr, cmdParams); }
//添加 protected void Button1_Click(object sender, EventArgs e) { if (Button1.Text == "添加分类") { Button1.Text = "更新"; M_Cate temp=new M_Cate(); if (TextBox1.Text == "") return; temp.CateName = TextBox1.Text; if (B_Cate.Add(temp)) { string str = " <script>alert('Add success'); </script>"; Response.Write(str); } Bind(); } if (Button1.Text == "更新") { Button1.Text = "添加分类"; M_Cate temp = new M_Cate(); temp.CateName = TextBox1.Text; B_Cate.Update(temp); Bind(); } }
public bool Add(M_Cate cate) { string sqlStr = "INSERT INTO ZL_Cate(CateName) VALUES(@CateName)"; SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = new SqlParameter("@CateName", SqlDbType.NVarChar, 50); parameter[0].Value = cate.CateName; return SqlHelper.ExecuteSql(sqlStr, parameter); }
private static SqlParameter[] GetParameters(M_Cate cate) { SqlParameter[] parameter = new SqlParameter[2]; parameter[0] = new SqlParameter("@CateName", SqlDbType.NVarChar,50); parameter[0].Value = cate.CateName; parameter[1] = new SqlParameter("@CateID", SqlDbType.Int); parameter[1].Value = cate.CateID; return parameter; }
public M_Cate GetCateByid(int cateId) { string sqlStr = "select * from ZL_Cate where cateid="+cateId; DataSet ds = SqlHelper.ExecuteDataSet(CommandType.Text, sqlStr, null); M_Cate temp = new M_Cate(); if (ds.Tables[0].Rows.Count == 0) return null; temp.CateID = Convert.ToInt32(ds.Tables[0].Rows[0][0]); temp.CateName=Convert.ToString(ds.Tables[0].Rows[0][1]); return temp; }
public static bool Update(M_Cate cateInfo) { return cate.Update(cateInfo); }
public static bool Add(M_Cate cateInfo) { return cate.Add(cateInfo); }
//全选 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "mydelete") { for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox IdCheck; IdCheck = (CheckBox)GridView1.Rows[i].FindControl("nameCheckBox"); if (IdCheck.Checked) { B_Cate.DeleteByID(Convert.ToInt32(e.CommandArgument.ToString())); Bind(); } } } if (e.CommandName == "myupdate") { Session.Add("cateid", e.CommandArgument); M_Cate tempcate=new M_Cate(); tempcate=B_Cate.GetCateByid(Convert.ToInt32( e.CommandArgument.ToString())); TextBox1.Text =tempcate.CateName; Button1.Text = "更新"; } if (e.CommandName == "mylink") { Response.Redirect("datamanage.aspx?cateid="+e.CommandArgument); Response.End(); } }
private static SqlParameter[] GetParameterss(M_Cate cate) { SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = new SqlParameter("@CateID", SqlDbType.Int); parameter[0].Value =cate.CateID; return parameter; }
protected void Page_Load(object sender, EventArgs e) { M_Cate temp = new M_Cate(); int CateID = Convert.ToInt32(Request.QueryString["cateid"]); Session.Add("CateId",CateID); temp = B_Cate.GetCateByid(CateID); this.Label2.Text = temp.CateName; if (!Page.IsPostBack) { Bind(); } }