代码中缺少什么? 有什么建议?
错误显示如下: -
Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error (missing operator) in query expression 'orderID =1AND productID ='.
/mcartfree/addToCart.asp, line 49
代码到目前为止
'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"))
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
新错误
Error Type:
Microsoft JET Database Engine (0x80004005)
Operation must use an updateable query.
/mcartfree/addToCart.asp, line 19
现在再次出现新错误
Error Type:
Microsoft JET Database Engine (0x80004005)
Operation must use an updateable query.
/mcartfree/addToCart.asp, line 31
答案 0 :(得分:3)
您可能缺少空格orderID = 1 AND productID =
而不是orderID =1AND productID =
。
我的案例系统找不到AND
运算符,因为它在查询中表示为1AND
字段的值orderId
。
使用以下内容更新您的查询:
sqlText = "SELECT * FROM itemsOrdered WHERE orderID = " & intOrderID & " AND productID = " & intProdID
set rsOrder = Conn.Execute(sqlText)
^ ^ ^
whitespace whitespace!!! whitespace
答案 1 :(得分:0)
写出你的SQL字符串,看看它是否正确:
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)