sql server - Update Sql database via editing Textbox C# -
i've got winform update sql database editing 2 textbox product name , product cost, doesn't update database, here sample code
private void simplebutton5_click(object sender, eventargs e) { string id = combobox2.items[combobox2.selectedindex].tostring(); string name = txtprodname.text; string cost = txtproductcost.text; cn.open(); string query = "update [product1] set [product_name]= @product_name,[product_cost]= @product_cost [product_id]= @product_id"; sqlcommand cmd = new sqlcommand(query, cn); cmd.parameters.addwithvalue("@product_id", id); cmd.parameters.addwithvalue("@product_name", name); cmd.parameters.addwithvalue("@product_price", cost); try { cmd.executenonquery(); messagebox.show("update succesfully"); } catch (exception ex) { messagebox.show(ex.message, application.productname, messageboxbuttons.ok, messageboxicon.error); } cn.close(); }
the datatype of id char
, product_name nvarchar(50)
, porduct_cost bigint
. thoughts appreciated
first, convert string value int
string cost = txtproductcost.text; costval=int.parse(cost)// costval integer
next, update database
cmd.parameters.addwithvalue("@product_price", costval);