Ms-Access:加入3个表

时间:2009-05-23 17:06:00

标签: vb.net ms-access

有没有人有一个如何连接3个表的例子,我有以下语句,但我得到了一个缺失的a(语法错误“操作符错误”)

da = New OleDbDataAdapter("SELECT [S].[Scheduled Vege], [V].[Description], 
        [DS].[Task], [DS].[Task Date], [DS].[Completed] FROM [Scheduled] AS S 
        INNER JOIN [Date Schedules] AS DS ON [S].[SchedID] = [DS].[SchedID] 
        INNER JOIN [Vegetables Descriptions] AS V ON [V].[Task] = [DS].[Task] 
        WHERE [DS].[TaskNumber] >= " & aFromDate & " AND [DS].[TaskNumber] <= " & aToDate & " 
        AND [DS].[Completed] = '" & aCompleted & "' ", conn)

感谢

3 个答案:

答案 0 :(得分:5)

发现问题,因为它是一个访问数据库,第一个来自语句,INNER JOIN需要在括号中,如下所示。

da = New OleDbDataAdapter("SELECT [S].[Scheduled Vege], [V].[Description], 
[DS].[Task], [DS].[Task Date], [DS].[Completed] FROM ([Scheduled] AS S 
INNER JOIN [Date Schedules] AS DS ON [S].[SchedID] = [DS].[SchedID]) 
INNER JOIN [Vegetables Descriptions] AS V ON [V].[Task] = [DS].[Task] 
WHERE [DS].[TaskNumber] >= " & aFromDate & " AND [DS].[TaskNumber] <= " & aToDate & " 
AND [DS].[Completed] = '" & aCompleted & "' ", conn)

答案 1 :(得分:0)

如果删除WHERE子句,您的查询是否会执行?立即跳出来的唯一一件事就是你的日期不一定是OleDB提供商想要的格式。

我的猜测是,您需要将日期封装为“2009年1月1日”或类似内容。

答案 2 :(得分:0)

您的加入看起来没问题,但我认为您的问题可能在于您将“TaskNumber”与“aFromDate”进行比较;数字和日期在SQL中是不同的类型,并且应该导致尝试比较它们的问题。