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:

  1. check if combobox1 , combobox2 (namming please) should have value of iduser , idclient in int type (for asp combobox, has value , text. text display users , value hidden, can used getting id this).

  2. 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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -