我正在调试以下代码并获得异常: 查询表达式中的语法错误(缺少运算符)" data1.PS NO = data2.PS N'。
代码是:
If data1 Is Nothing And data2 Is Nothing Then
MsgBox("Open two excel files to generate report", MsgBoxStyle.Information, "Try Again")
Else
cntcn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'"
oleConnection = New System.Data.OleDb.OleDbConnection(cntcn)
oleCommand = New System.Data.OleDb.OleDbDataAdapter("SELECT May FROM [data1] INNER JOIN [data2] ON data1.PS NO=data2.PS NO WHERE data1.Month = 'May'", oleConnection)
oleCommand.Fill(data3)
End If
这里我创建了两个数据表data1和data2并应用了内连接查询。但是得到了上述异常 请帮忙。 提前谢谢。
答案 0 :(得分:0)
oleCommand = New System.Data.OleDb.OleDbDataAdapter("SELECT data1.Month FROM [data1] INNER JOIN [data2] ON data1.[PS NO]=data2.[PS NO] WHERE data1.Month = 'May'", oleConnection)
问题:
您:SELECT May
更改为data1.[Month]
将此更改为data1.PS NO
:data1.[PS NO]