www.webdeveloper.com
Results 1 to 3 of 3

Thread: Data type mismatch in criteria expression.

  1. #1
    Join Date
    Sep 2003
    Posts
    5

    Data type mismatch in criteria expression.

    I am working on an update for my product table and I am getting the following error:

    Microsoft JET Database Engine error '80040e07'

    Data type mismatch in criteria expression.

    /info3240/Diesel/Angie/ASP4/recUpdate.asp, line 15


    I have checked and double checked the names in my database and I know they are correct. The Product_ID is what is giving me the problem, I am assuming, but I can not figure out where I've gone wrong.

    here is the recUpdate.asp file that is giving me the error

    <html>
    <body><h2>Update Record</h2>
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open server.mappath ("Products.mdb")

    id=Request.Form("Product_ID")

    if Request.form("Category_ID")="" then
    set rs=Server.CreateObject("ADODB.Recordset")
    rs.open "SELECT * FROM Products WHERE Product_ID='" & id &"'" ,conn
    %>

    <form method="post" action="recUpdate.asp">
    <table>
    <%for each x in rs.Fields%>
    <tr>
    <td><%=x.name%></td>
    <td><input name="<%=x.name%>" value="<%=x.value%>"></td>
    <%next%>
    </tr>
    </table>
    <br /><br />
    <input type="submit" value="Update record">
    </form>
    <%
    else
    sql="UPDATE Products SET "
    sql=sql & "Category_ID='" & Request.Form("Category_ID") & "',"
    sql=sql & "Product_Name='" & Request.Form("Product_Name") & "',"
    sql=sql & "Price='" & Request.Form("Price") & "',"
    sql=sql & "Quantity='" & Request.Form("Quantity") & "'"
    sql=sql & " WHERE Product_ID='" & id & "'"
    on error resume next
    conn.Execute sql
    if err<>0 then
    response.write("No update permissions!")
    else
    response.write("Record " & id & " was updated!")
    end if
    end if
    conn.close
    %></body>
    </html>

    --------------Here is the update.asp file that directs the user to the recupdate.asp---------------------------------------------

    <html>
    <body>
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open server.mappath("Products.mdb")

    set rs=Server.CreateObject("ADODB.Recordset")
    rs.open "SELECT * FROM Products",conn
    %>

    <h2>Product List</h2>
    <font style = "color:red">Click on a Product ID in the table below
    to change the entry </font>

    <table border="1" width="100%">
    <tr>
    <%
    for each x in rs.Fields
    response.write("<th>" & ucase(x.name) & "</th>")
    next
    %>
    </tr>

    <% do until rs.EOF %>

    <tr>
    <form method="post" action="recUpdate.asp">
    <%
    for each x in rs.Fields
    if x.name="Product_ID" then%>
    <td>
    <input type="submit" name="Product_ID" value="<%=x.value%>">
    </td>

    <%else%>
    <td><%Response.Write(x.value)%></td>

    <%end if
    next
    %>
    </form>

    <%rs.MoveNext%>

    </tr>
    <%
    loop
    conn.close
    %>
    </table></body>
    </html>
    Any ideas?

    Thanks so much

  2. #2
    Join Date
    Nov 2003
    Posts
    6
    This is probubly problem with data types
    Let say if you have in database field "Product_ID" setup as integer datatype the line in your code:
    rs.open "SELECT * FROM Products WHERE Product_ID='" & id &"'" ,conn
    my cause the problem

    To fix it use:
    SELECT * FROM Products WHERE Product_ID=" & id ,conn

    hope it will work for you

  3. #3
    Join Date
    Sep 2003
    Posts
    5
    Worked like a charm. I feel like an idiot now though!

    Thank you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles