c# - Error while adding a new record from text boxes to database -
error when saving info database. dataadapter.fill(ds,"table") throwing sqlexception saying error while converting info type nvarchar numeric.
private void btnsave_click_1(object sender, eventargs e) { da = new sqldataadapter(); da.selectcommand = new sqlcommand("select * measurement id = @id", con); da.selectcommand.parameters.addwithvalue("@id",txtid.text); sqlcommandbuilder cb = new sqlcommandbuilder(da); da.fill(ds, "measurement"); //(sqlexception unhandled)error converting info type nvarchar numeric. if (string.isnullorempty(txtcellno.text.trim())) { messagebox.show("please come in cell number"); } else { seek { dr = ds.tables["measurement"].rows[0]; dr["cellnumber"] = txtcellno.text.trim(); dr["firstname"] = txtfirstname.text; dr["lastname"] = txtlastname.text; dr["shirt"] = txtshirt.text; dr["pant"] = txtpant.text; dr["duedate"] = txtduedate.text; dr["date"] = txtdate.text; cb.getupdatecommand(); da.update(ds, "measurement"); } grab (exception ex) { messagebox.show(ex.message); } } }
this line:
da.selectcommand.parameters.addwithvalue("@id",txtid.text);
txtid.text
string need convert integer. see int.tryparse
c# winforms
No comments:
Post a Comment