Update Statement into Textboxes c# data type mismatched in criteria -


attempting use update statement when execute program claims: user type mismatch in data criteria

when click updatebutton, want database update id =

private void update_click(object sender, eventargs e) {     //opening connection      db.open();     int idd = int.parse( instructoridtext.text);      oledbcommand df = new oledbcommand("update instructors set firstname='"+fntext.text+"',lastname='"+lntext.text+"',street='"+streettext.text+"',city='"+citytext.text+"',state='"+statetext.text+"',zip='"+ziptext.text+"',office='"+officetext.text+"',email='"+emailtext.text+"' id = " + idd +"", db);     //creating parameters     df.parameters.addwithvalue("@id", instructoridtext.text);      df.parameters.addwithvalue("@firstname", fntext.text);     df.parameters.addwithvalue("@lastname", lntext.text);     df.parameters.addwithvalue("@street", streettext.text);     df.parameters.addwithvalue("@city", citytext.text);     df.parameters.addwithvalue("@state", statetext.text);     df.parameters.addwithvalue("@zip", ziptext.text);     df.parameters.addwithvalue("@office", officetext.text);     df.parameters.addwithvalue("@email", emailtext.text);     df.executenonquery();     db.close(); } 

use @parameter in query instead of concatenating exact values

for ms-sql

//opening connection  db.open(); int idd = int.parse(instructoridtext.text);  oledbcommand df = new oledbcommand("update instructors set firstname=@firstname,lastname=@lastname,street=@street,city=@city,state=@state,zip=@zip,office=@office,email=@email id = @id", db); //creating parameters df.parameters.addwithvalue("@id", instructoridtext.text);  df.parameters.addwithvalue("@firstname", fntext.text); df.parameters.addwithvalue("@lastname", lntext.text); df.parameters.addwithvalue("@street", streettext.text); df.parameters.addwithvalue("@city", citytext.text); df.parameters.addwithvalue("@state", statetext.text); df.parameters.addwithvalue("@zip", ziptext.text); df.parameters.addwithvalue("@office", officetext.text); df.parameters.addwithvalue("@email", emailtext.text); df.executenonquery(); db.close(); 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -