Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Error: DataType Mismatch...

    Ok,

    Can anyone tell me why I am getting the following error:

    Microsoft JET Database Engine error '80040e07'
    Data type mismatch in criteria expression.
    /bl/iteminquiry.asp, line 18

    Here is the code for this:

    ID = request("ID")
    strSQL = "Select * From Products where ProductID = '" & ID & "' " ' This is line 18
    Set objRS = objConn.Execute(strSQL)


    I have a Products Table and I am trying to pull a record based on the Primary Key(AutoNumber) and keep getting this error. Is there anything wrong with my syntax?

    Thanks,

    tsbarnes

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    India
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try
    Code:
    strSQL = "Select * From Products where ProductID = " & ID
    Since the primary key ID is an autonumber you shouldn't give it withing quotes.

  • #3
    New Coder
    Join Date
    Jan 2003
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    codefox,

    The line of code works if I hard code the value of my variable.

    ID = "15"

    But if i do

    ID = Request("ID")
    strSQL = "Select * From Products where ProductID =" & ID

    Then I get this error:

    Microsoft JET Database Engine error '80040e14'
    Syntax error (missing operator) in query expression 'ProductID ='.
    /bl/iteminquiry.asp, line 17


    So I am unclear why this is not working!

    Thanks,

    tsbarnes

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    The sunny side of the Alps
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The problem is that your ID value is '' - use either Request.QueryString("ID") or Request.QueryString("ID") to write the value into ID.
    Bostjan

  • #5
    New Coder
    Join Date
    Jan 2003
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    bostjank,

    I don't understand what you are saying. Can you explain it a little more?


    Thanks,

    tsbarnes

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    The sunny side of the Alps
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you use Response.Write to print SQL statement to the screen, you'll see, that ID variable's value is empty:
    Code:
    Select * From Products where ProductID =
    The reason for this is that you don't set any value to variable named ID. To set value to this variable try using Request.Form or Request.QueryString (depending on the type of request).
    Also check if the field's name or querystring name is correct.

    Bostjan

  • #7
    New Coder
    Join Date
    Jan 2003
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok,

    Finally, I got it all figured out. Thanks Bostjan for telling to print my sql statement. In doing this I realized that in my <form Action=> I was submitting the form to itself but I wasn't including the ProductID and therefore when I clicked submit it was wiping out the ProductID and therefore getting an error!

    Thanks,

    tsbarnes

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, that's the first step I take in debugging any SQL statement:

    SQL = "whatever"
    'Response.Write(SQL) : Response.END 'Uncomment this line to test!
    Conn.Execute(SQL)

    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •