By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,500 Members | 1,571 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,500 IT Pros & Developers. It's quick & easy.

Syntax error (missing operator) in query

P: 1
I am trying to finish my final project for my programing class. i keep on getting Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'OrderID ='.
/students/11/scripts/OrdersLines.asp, line 12

I place the ' ;' and then i recieve
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
/students/11/scripts/OrdersLines.asp, line 12


can anyone help me
Expand|Select|Wrap|Line Numbers
  1. <%
  2. OrderID = request.QueryString("OrderID")
  3. Set conn = Server.CreateObject("ADODB.Connection")
  4. conn.open "Prj11"
  5. SQLCmd = "Select CustomerID, LogTime, Description, ShippingAddress, SCity, SZipCode, SState, BillingAddress, BCity, BZipCode, BState, OrderID FROM Orders WHERE OrderID = " & OrderID & ""  (Line 12)
  6.  
  7. Set rsOrder = Conn.Execute(SQLCmd)
  8.  
  9. CustomerID = replace(rsOrder("CustomerID"),"'","''")
  10. LogTime = replace(rsOrder("LogTime"),"'","''")
  11. Description = replace(rsOrder("Description"),"'","''")
  12. ShippingAddress = replace(rsOrder("ShippingAddress"),"'","''")
  13. SCity = replace(rsOrder("SCity"),"'","''")
  14. SZipCode = replace(rsOrder("SZipCode"),"'","''")
  15. SState = replace(rsOrder("SState"),"'","''")
  16. BillingAddress = replace(rsOrder("BillingAddress"),"'","''")
  17. BCity = replace(rsOrder("BCity"),"'","''")
  18. BZipCode = replace(rsOrder("BZipCode"),"'","''")
  19. BState = replace(rsOrder("BState"),"'","''")
  20.  
  21. SQLCmd = "SELECT CustomerName FROM Customer WHERE CustomerID = '" & CustomerID & "'"
  22.  
  23. Set rsClient = Conn.Execute(SQLCmd)
  24. CustomerName = Replace(rsClient("CustomerName"),"'","''")
  25. %>
Dec 7 '09 #1
Share this Question
Share on Google+
2 Replies


P: 3
aaron6098,

Your problem is probably because of order Id value being blank in the querystring...

Try printing out OrderID variable before you use it in SQL..

Also, alternatively to nail the issue, you can hard-code the OrderId in SQL and see if it works...

But, my guess is you are probably missing orderId value in SQL...also try printing SQL before firing it to database engine..

Hope this helps you to get to issue.
Dec 9 '09 #2

jhardman
Expert 2.5K+
P: 3,405
Vipin is quite likely right, but in the end, this is a common problem with a simple solution: print out your query (response.write SQLCMD) and LOOK AT IT! When you look at the final query there is a 90% chance you will see the problem. My first guess: too many quote marks. Numerical fields should not be within single quote marks in a SQL query. "...WHERE customerID = '1234'" is almost definitely wrong (this is in the second query, but it illustrates the point). The line 12 ends with 2 quote marks for some reason. I can't tell why. It is fine to say
Expand|Select|Wrap|Line Numbers
  1. SQLCmd = "Select CustomerID, LogTime, Description, ShippingAddress, SCity, SZipCode, SState, BillingAddress, BCity, BZipCode, BState, OrderID FROM Orders WHERE OrderID = " & OrderID
of course, if vipin is correct and orderID is blank, then if you printed out the query, you would see
Expand|Select|Wrap|Line Numbers
  1. Select CustomerID, LogTime, Description, ShippingAddress, SCity, SZipCode, SState, BillingAddress, BCity, BZipCode, BState, OrderID FROM Orders WHERE OrderID = 
So to recap, the solution is to print out your query and look at it!

Jared
Dec 21 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.