我的vb.net软件中的from子句出现语法错误,任何人都可以帮助我????
Private Sub txtSearchByDish_TextChanged(sender As Object, e As EventArgs) Handles txtSearchByDish.TextChanged
Try
con = New OleDbConnection(cs)
con.Open()
cmd = New OleDbCommand("SELECT DishName, I.Rate, SUM([Qty]) as ItemQuantity, BillDate, ( I.Rate * SUM([Qty])) As TotalAmount FROM Dish as I, RestaurantBillingInfo as P, RestaurantBillingItems as PD, WHERE DishName like '" & txtSearchByDish.Text & "%' order by DishName", con)
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dgw.Rows.Clear()
While (rdr.Read() = True)
dgw.Rows.Add(rdr(0), rdr(1), rdr(2), rdr(3), rdr(4))
End While
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
答案 0 :(得分:1)
您无法用逗号结束FROM
子句。
更改RestaurantBillingItems as PD, WHERE
至RestaurantBillingItems as PD WHERE
请注意,您的程序是您的程序容易受到SQL注入
另请注意,您使用的是聚合,而不是BillDate
,DishName
和I.Rate
分组,而且它们不是聚合。您可能希望为它们使用聚合,或者按它们分组,例如GROUP BY BillDate, DishName, I.Rate