Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   Visual basic 6 - Data mismatch (https://www.askmehelpdesk.com/showthread.php?t=524870)

  • Nov 11, 2010, 05:18 AM
    MUHAIMEN
    visual basic 6 - Data mismatch
    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.
  • Nov 11, 2010, 06:54 AM
    stagepic

    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
  • Nov 23, 2010, 07:14 AM
    GaryStaunton
    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.
    :-)
  • Nov 23, 2010, 07:33 AM
    GaryStaunton
    Comment on GaryStaunton's post
    I have assumed that the database field is a TEXT field, if not, let me know. My example above is for a TEXT field.
  • Nov 23, 2010, 10:50 PM
    GaryStaunton
    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.

  • Nov 25, 2010, 09:30 PM
    MUHAIMEN
    Comment on GaryStaunton's post
    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. :)

  • All times are GMT -7. The time now is 06:47 AM.