开发者

Adding to cart problem (What am I missing)

What am missing in code? Any suggestions?

Error display like this:-

Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error (missing operator) in query expression 'orderID =1AND productID ='.
/mcartfree/addToCart.asp, line 49

Code is so far

'Main program 
 Sub CreateNewOrder()
    Application.lock
    if Application("orderID") = "" then
        Application("orderID") = 1
    end if


   intOrderID = Application("orderID")
   Session("orderID") = intOrderID
   Conn.Execute("INSERT INTO orders " _
    & " (orderID, status) values " _
    & " ("&intOrderID&", 'OPEN')")

    Application("orderID") = Application("orderID") + 1
   Application.Unlock
End Sub

Sub AddToOrder(nOrderID, nProductID, nQuant)
    sqlText = "INSERT INTO itemsOrdered " _
        & " (orderID, productID, quantity) values " _ 
        & " ("&nOrderID&", "&nProductID&", "&nQuant&")"
    Conn.Execute(sqlText)

End Sub


'Main program 
intProdID = Request.form("intProdID")
intQuant = Request.form("intQuant")

set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString

intOrderID = cstr(Session("orderID开发者_StackOverflow社区"))
if intOrderID = "" then
   CreateNewOrder
end if

sqlText = "SELECT * FROM itemsOrdered WHERE orderID =" & intOrderID & "AND productID =" & intProdID
set rsOrder = Conn.Execute(sqlText)

if rsOrder.EOF then
    txtInfo = "This item has been added to your order."  
    AddToOrder intOrderID, intProdID, intQuant
else
    txtInfo = "This item is already in your cart."
end if

New Error

Error Type:
Microsoft JET Database Engine (0x80004005)
Operation must use an updateable query.
/mcartfree/addToCart.asp, line 19

Now again the new error

Error Type:
Microsoft JET Database Engine (0x80004005)
Operation must use an updateable query.
/mcartfree/addToCart.asp, line 31


Probably you are missing whitespace orderID = 1 AND productID = instead of orderID =1AND productID =.

I your case system can't find AND operator becuase it's represented in query like value 1AND for orderId field.

Update your query with the following:

sqlText = "SELECT * FROM itemsOrdered WHERE orderID = " & intOrderID & " AND productID = " & intProdID
set rsOrder = Conn.Execute(sqlText)
                                                     ^                  ^               ^
                                                 whitespace         whitespace!!!   whitespace


Write out your SQL string and see if its correct:

sqlText = "SELECT * FROM itemsOrdered WHERE orderID = " & intOrderID & " AND productID = " & intProdID
' Debug sql...
Response.Write(sqlText)
Response.End()
' Just debuging the SQL statement....

set rsOrder = Conn.Execute(sqlText)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜