1
我試圖通過CustomerID選擇最新的OrderID。但它一直說我的SQL語法有錯誤,即使它在PhpMyAdmin中有效。我使用的是MySQL
db和ODBC connector
。使用'限制'的MySQL聲明錯誤
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。
任何人都可以看到我可能做錯了嗎?謝謝!
下次請提供整個錯誤信息,謝謝。 – Bobby 2011-05-19 10:03:19