Ask Experts Questions for FREE Help !
Ask
    MUHAIMEN's Avatar
    MUHAIMEN Posts: 44, Reputation: 1
    Junior Member
     
    #1

    Nov 11, 2010, 05:18 AM
    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.
    stagepic's Avatar
    stagepic Posts: 4, Reputation: 1
    New Member
     
    #2

    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's Avatar
    GaryStaunton Posts: 17, Reputation: 2
    New Member
     
    #3

    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's Avatar
    GaryStaunton Posts: 17, Reputation: 2
    New Member
     
    #4

    Nov 23, 2010, 07:33 AM
    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.
    GaryStaunton's Avatar
    GaryStaunton Posts: 17, Reputation: 2
    New Member
     
    #5

    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's Avatar
    MUHAIMEN Posts: 44, Reputation: 1
    Junior Member
     
    #6

    Nov 25, 2010, 09:30 PM
    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. :)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Visual basic 6 [ 1 Answers ]

Hi! I am facing difficulty in preparing SRS(software requirement specification) of my semister project which is Credit Card System(visual basic 6) please give me some suggesion. Thank you

Visual Basic [ 1 Answers ]

Actually I'm a new user(student) of Visual Basic.So I want to know how I am make a simple calculator in Visual Basic 6?


View more questions Search