vb.net 2010 express 中的以下代码会生成此错误:
查询表达式 '' 中的语法错误(缺少运算符)。
sql = "SELECT Machines.LocationID FROM Lanes LEFT JOIN Cabinets ON
Lanes.CabinetID=Cabinets.ID AND Cabinets.Name IS NOT NULL LEFT JOIN Machines ON
Cabinets.MachineID=Machines.ID "
Dim mAdapter As New OleDbDataAdapter(sql, con)
Dim mt As New DataTable("Results")
mAdapter.Fill(mt)
con
在项目的一个模块中定义为:
Public myConString As String = "Provider=Microsoft.ACE.OLEDB.12.0"
Public databaseName As String = "C:\vending.mdb"
Public con As New OleDb.OleDbConnection(myConString & ";Data Source =" & databaseName)
如果我注释掉第二个 Left Join 命令,则该语句将正确执行。从 SQL Server 执行时,这条完全相同的 sql 语句可以正常工作。
表定义为:
地点
ID INTEGER IDENTITY
Company
Name
...
机器
ID INTEGER IDENTITY
LocationID Integer
Name as Text(100)
SerialNum as Text(100)
...
橱柜
ID INTEGER IDENTITY
Name TEXT(100)
MachineID INTEGER
...
车道
ID INTEGER IDENTITY
Name TEXT(100)
CabinetID INTEGER
...
如果我在连接语句周围添加括号,如下所示:
sql = "SELECT Machines.LocationID FROM ((Lanes LEFT JOIN Cabinets ON
Lanes.CabinetID=Cabinets.ID AND Cabinets.Name IS NOT NULL) LEFT JOIN Machines ON
Cabinets.MachineID=Machines.ID) "
我得到错误:
不支持连接表达式。
请帮忙!