c# - Data type mismatch in criteria expression Access 2013 -
oledbcommand computerstatus = new oledbcommand("update computer set status= 'occupied' pcnumber='" + cbocomputerno.text + "'", con); computerstatus.executenonquery();
this code. pcnumber autonumber getting error wants me alter info type string need autonumber.
autonumber
auto number. since numerical value, don't need utilize single quotes it.
but more important, should utilize parameterized queries. kind of string concatenations open sql injection attacks.
also utilize using
statement dispose oledbconnection
, oledbcommand
.
using(oledbconnection con = new oledbconnection(constring)) using(oledbcommand computerstatus = con.createcommand()) { computerstatus.commandtext = "update computer set status= ? pcnumber = ?"; computerstatus.parameters.addwithvalue("@status", "occupied"); computerstatus.parameters.addwithvalue("@number", cbocomputerno.text); computerstatus.executenonquery(); }
as larstech pointed, may wanna check cbocomputerno.text
string valid integer using int.tryparse
method.
c# ms-access insert-update
No comments:
Post a Comment