Data type mismatch in criteria expression - Access and C#

A problem I came across not so long ago, with a simple solution. This happens if you are updating or inserting data into an access database and using an incorrect type. For instance:

If your column in access is of type Text, this error will occur when you are updating a row with a value of type Int or something other than text.

This is what caused the error:

[box] cmdStatusQueue = new OleDbCommand(“update connectSentItems set sentstatus = ‘” + mappedStatus + “‘ where ID = ‘” + statusSplitstring[0]+”‘”, conStatusQueue); [/box]

It might not be very visible here, but basically what the problem is, is that there should be no ‘ surrounding statusSplitstring[0] – the problem is corrected as follows:

[box] cmdStatusQueue = new OleDbCommand(“update connectSentItems set sentstatus = ‘” + mappedStatus + “‘ where ID = ” + statusSplitstring[0], conStatusQueue); [/box]

The error occured due to ID being of type int and in the first example I was trying to assign it a text based value from the ‘ character.

Hope this helps!

Cheerio 🙂

Turkey Tunnel Logo