c# - Update query updates all records except the name -
i stuck issue updating. when open windows form developed in c# using sql, update updates fields not name. tell me did wrong?
here code
public void cc() { cbbname.items.clear(); sqlcommand cmd = new sqlcommand(); cmd.commandtype = commandtype.text; cmd.commandtext = "select * bkhurdata"; db.exenonquery(cmd); datatable dt = new datatable(); sqldataadapter da = new sqldataadapter(cmd); da.fill(dt); foreach (datarow dr in dt.rows) { cbbname.items.add(dr["name"].tostring()); } } private void bkhurupdate_click(object sender, eventargs e) { sqlcommand cmd = new sqlcommand(); cmd.commandtype = commandtype.text; cmd.commandtext = "update bkhurdata set name='" + tbbpname.text + "',details='" + tbbpdetails.text + "',price='" + tbbpprice.text + "',size='" + tbbpsize.text + "', quantity ='"+tbbpquantity.text+"' name = '" + tbbpname.text + "'"; db.exenonquery(cmd); tbbpname.text = ""; tbbpdetails.text = ""; tbbpprice.text = ""; tbbpsize.text = ""; tbbpquantity.text = ""; cc(); messagebox.show("updated successfully"); }
you updating name
name
equals tbbpname.text
not change name row updating.
private string originalname; public void cc() { cbbname.items.clear(); sqlcommand cmd = new sqlcommand(); cmd.commandtype = commandtype.text; cmd.commandtext = "select * bkhurdata"; db.exenonquery(cmd); datatable dt = new datatable(); sqldataadapter da = new sqldataadapter(cmd); da.fill(dt); foreach (datarow dr in dt.rows) { cbbname.items.add(dr["name"].tostring()); originalname = dr["name"].tostring() } } private void bkhurupdate_click(object sender, eventargs e) { sqlcommand cmd = new sqlcommand(); cmd.commandtype = commandtype.text; cmd.commandtext = "update bkhurdata set name='" + tbbpname.text + "',details='" + tbbpdetails.text + "',price='" + tbbpprice.text + "',size='" + tbbpsize.text + "', quantity ='"+tbbpquantity.text+"' name = '" + originalname+ "'"; db.exenonquery(cmd); tbbpname.text = ""; tbbpdetails.text = ""; tbbpprice.text = ""; tbbpsize.text = ""; tbbpquantity.text = ""; cc(); messagebox.show("updated successfully"); }
Comments
Post a Comment