我正在尝试按CustomerID选择最新的OrderID。但它一直说我的SQL语法有错误,即使它在PhpMyAdmin中有效。我正在使用MySQL
数据库和ODBC connector
。
Public Function GetOrderIDByCustID(ByVal CustID As Integer) As Integer
myconn.Open()
Dim OrderID As Integer = 0
Dim OrderSQL As String =
"SELECT OrderID
FROM Order
WHERE OrderCustID= ? AND OrderArchived = 0
ORDER BY OrderDate DESC LIMIT 1"
Dim cmd As New OdbcCommand("OrderSQL", myconn)
cmd.Parameters.AddWithValue("OrderCustID", CustID)
OrderID= cmd.ExecuteScalar()
myconn.Close()
Return OrderID
End Function
所以这应该为我提供该客户最新订单的OrderID。
任何人都可以看到我可能做错了吗?谢谢!
答案 0 :(得分:1)
Dim cmd as New OdbcCommand("OrderSQL", myconn)
OrderSQL不应该在括号中,解决方案是:
Dim cmd as New OdbcCommand(OrderSQL, myconn)
多么蹩脚大声笑..