Log in

View Full Version : Visual basic 6 - Data mismatch


MUHAIMEN
Nov 11, 2010, 05:18 AM
Private Sub cmdsearch_Click()
Dim qry As String
qry = "select * from [heavy equipment] where codeno=" & Val(txtsearchcode.Text)


searchheavyfiles.RecordSource = qry
searchheavyfiles.Refresh

End Sub
========================
The code above after running it show error message ADODC1-Data type mismatch in criteria expression. Is there any body who can tell me the problem? Thanks in advance.

stagepic
Nov 11, 2010, 06:54 AM
my visual basics is not to hot but you can try:
codeno= '" & Val(txtsearchcode.Text) & "'"
that way you quote the txtsearchcode.Text and ensure it's a string. If that doesn't work try adding single quotes to codeno as well:
codeno & '' = '"
that way you quote the txtsearchcode.Text and ensure its a string. If that doesn't work try adding single quotes to codeno as well:
codeno & '' = '"'"
now both sides are cast to strings

GaryStaunton
Nov 23, 2010, 07:14 AM
Simply put (copy+paste friendly):
qry = "SELECT * FROM [heavy equipment] WHERE codeno= '" & txtsearchcode.Text & "'"

Basically your code needs o connect to a valid data type... From the name (txtsearchcode.text) would assume a string value, if your database field is numeric, then the query IS expecting a number value, hence my response, I am assuming that the DB field is setup as a Text field (by default).

Other options/solutions are available depending on the set that types etc.
:-)

GaryStaunton
Nov 23, 2010, 07:33 AM
I have assumed that the database field is a TEXT field, if not, let me know. My example above is for a TEXT field.

GaryStaunton
Nov 23, 2010, 10:50 PM
The error relates to the database field type:
qry = "select * from [heavy equipment] where codeno=" & Val(txtsearchcode.Text)

If the field codeno in the database is defined as being a text field, then the error ADODC1-Data type mismatch in criteria expression will be returned to you. Try adding quotes to the query:

qry = "SELECT * FROM [heavy equipment] WHERE codeno='" & Val(txtsearchcode.Text) & "'"

Hope that helps.

MUHAIMEN
Nov 25, 2010, 09:30 PM
Thanks gary, I found that the field is text not numeric. I am using the code with dash e.g 25-21,25-22-25-23 and so on. Thanks a lot for the information. :)