c# - Conversion failed when converting the varchar value to data type int in SQL Server query Windows Forms -
i add record in database.
there code below :
private void buttonadd_click(object sender, eventargs e) { con.open(); sqldataadapter sda = new sqldataadapter("insert rdv (iduser,idclient,objet,objectif,daterdv,commentaire)values('"+combobox1.text+"','"+combobox2.text+ "','" + textbox1.text + "','" + textbox2.text + "','" + datetimepicker1.text.tostring() + "','" + textbox4.text + "')", con); sda.selectcommand.executenonquery(); con.close(); messagebox.show("le rdv été ajouté avec succés !"); }
but error happens:
conversion failed when converting varchar value 'john' data type int.
how should convert it? please me.
thanks in advance.
for information table rdv
, problem 2 fields: iduser
, idclient
. think should:
check if
combobox1
,combobox2
(namming please) should have value ofiduser
,idclient
in int type (for asp combobox, has value , text. text display users , value hidden, can used getting id this).get right ids using
combobox1.selectedvalue
,combobox2.selectedvalue
:sqldataadapter sda = new sqldataadapter("insert rdv(iduser,idclient,objet,objectif,daterdv,commentaire)values("+combobox1.selectedvalue+","+combobox2.selectedvalue+ ",'" + textbox1.text + "','" + textbox2.text + "','" + datetimepicker1.text.tostring() + "','" + textbox4.text + "')", con);
just delete '
values(1, 4, 'the obj',...)
instead of values('1', '4', 'the obj',...)
Comments
Post a Comment