from子句中的语法错误。 vb.net

时间:2017-12-06 09:00:16

标签: vb.net ms-access

我的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

1 个答案:

答案 0 :(得分:1)

您无法用逗号结束FROM子句。

更改RestaurantBillingItems as PD, WHERE

RestaurantBillingItems as PD WHERE

请注意,您的程序是您的程序容易受到SQL注入

另请注意,您使用的是聚合,而不是BillDateDishNameI.Rate分组,而且它们不是聚合。您可能希望为它们使用聚合,或者按它们分组,例如GROUP BY BillDate, DishName, I.Rate