我收到异常错误,说缺少操作符可以帮助任何人
string sql = "Select SalesPerson.Name, Item.Description, Orders.Quantity, Orders.OrderDate"
+ "From([Orders]"
+ "Inner Join[SalesPerson] On Orders.SalesPersonID=SalesPerson.SalesPersonID)"
+ "Inner Join[Item] On Orders.ItemNumber=Item.ItemNumber"
+ "Where Orders.CustomerID=@customer Order by Orders.OrderDate DESC";
答案 0 :(得分:1)
您需要在每行SQL的末尾添加一些空格!
string sql = "SELECT SalesPerson.Name, Item.Description, Orders.Quantity, Orders.OrderDate "
+ "FROM [Orders] "
+ "INNER JOIN [SalesPerson] ON Orders.SalesPersonID = SalesPerson.SalesPersonID "
+ "INNER JOIN [Item] ON Orders.ItemNumber = Item.ItemNumber "
+ "WHERE Orders.CustomerID = @customer "
+ "ORDER BY Orders.OrderDate DESC";
否则,您的SQL最终会
Select ..... Orders.OrderDateFROM([Orders]Inner Join[SalesPerson] .....
依此类推 - 那只是 不 有效的SQL。
我还删除了JOIN
运算符周围的一些不必要的括号 - 这些只是MS Access需要的,但是因为你说你正在使用ADO.NET,我认为这是不用于MS Access,因此,不需要那些括号