I’m trying to select the newest OrderID by CustomerID. But it keeps saying I have an error in my SQL syntax, even though it works in PhpMyAdmin. I’m using a MySQL db and an 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
So this should supply me with the OrderID of the newest Order for that Customer.
Can anyone see what I might have done wrong? Thanks!
Ugh, I’ve been looking over it for an hour now ..
OrderSQL shouldn’t be in brackets, solution is:
How lame lol ..