mosemadl
asked on
Data type mismatch in criteria expression.
I've done this a million times, but I keep getting the error: Data type mismatch in criteria expression from the following code.
valCancel = DateTime.Now() & "-" & TracktionUser
strCancel = "Update CWE_Debug Set Cancel=@Cancel Where UserCode = '" & valUser & "' And ExamID = '" & valExam & "'"
cmdCancel = New OleDbCommand( strCancel, conTracktion )
cmdCancel.Parameters.Add( "@ExamID", OleDBType.Char).Value = valCancel
cmdCancel.ExecuteNonQuery( )
valCancel is defined as a string and the Cancel field in my Access DB is ShortText. I've tried to update other fields in the table and got the same error. So I thought my DB got corrupted and I run repair. Is there a line of code to ask what oledbtype its looking for? I'm completely stumped on this one. Anybody have any ideas?
valCancel = DateTime.Now() & "-" & TracktionUser
strCancel = "Update CWE_Debug Set Cancel=@Cancel Where UserCode = '" & valUser & "' And ExamID = '" & valExam & "'"
cmdCancel = New OleDbCommand( strCancel, conTracktion )
cmdCancel.Parameters.Add( "@ExamID", OleDBType.Char).Value = valCancel
cmdCancel.ExecuteNonQuery(
valCancel is defined as a string and the Cancel field in my Access DB is ShortText. I've tried to update other fields in the table and got the same error. So I thought my DB got corrupted and I run repair. Is there a line of code to ask what oledbtype its looking for? I'm completely stumped on this one. Anybody have any ideas?
Can you state what that code is suppose to be doing, ...you naming is throwing me off...
ASKER
I just need to update a field labeled 'Cancel' to be a string like "5/12/2015-Moseman".
Cstr([Cancel])
Note that "Cancel" is a bad name for a field, ..as it is a reserved word.
Note that "Cancel" is a bad name for a field, ..as it is a reserved word.
Note that you should be able to concatenate values to a ate field without Cstr()...
ASKER
According to this https://support.microsoft.com/en-us/kb/286335 its not a reserved word, but I'll try changing it anyway.
ASKER
Nope! I renamed the field to 'CancelStr' and I still get data type mismatch. No idea what type it thinks it is.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The filed name was not part of the issue, ..I merely mentioned the name as a note...
Lets be clear, ...did you then still wrapped the field in the cst() function:
Cstr(CancelStr)
...and you still got the error?
Lets be clear, ...did you then still wrapped the field in the cst() function:
Cstr(CancelStr)
...and you still got the error?
ok great
ASKER
I figured it out.