C# AND ACCESS - Data type mismatch in criteria expression -


i've created code updates/edits details of a/an computer/electronic product c# program connecting ms access. here codes:

oledbcommand cmd = new oledbcommand("update available set producttype = '" + newavailable.producttype + "', brand = '"+ newavailable.brand + "', model = '" + newavailable.model + "', serialno = '" + newavailable.serialno + "', remarks = '" + newavailable.remarks + "', ram = '" + newavailable.ram + "', hdd = '" + newavailable.hdd + "', odd = '" + newavailable.odd + "', videocard = '" + newavailable.videocard + "', ps = '" + newavailable.ps + "'  availableid = '"+oldavailable.availableid+"'", cnn); cmd.commandtype = commandtype.text; cnn.open(); cmd.executenonquery(); cnn.close(); 

availableid accepts int32 values , rest of variables string. program executable, yet c# detected error.

data type mismatch in criteria expression.

what should do?

i suspect you're not passing 1 of parameters correct availableid, instead try add parameters way:

var cmd = new oledbcommand {     connection = cnn,     commandtype = commandtype.text,     commandtext = "update available set producttype = ?, brand = ?, model = ?, serialno = ?, remarks = ?, ram = ?, odd = ?, videocard = ?, ps = ?  availableid = ?" };  cmd.parameters.add(new oledbparameter {value = newavailable.producttype}); cmd.parameters.add(new oledbparameter {value = newavailable.brand}); // add other parameters ... 

as side note, it's not idea generate queries concatenating strings anyway should use parameters.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -