我在C#TableAdapter中看到一些奇怪的行为,它来自Access。我有一个查询返回Access中的结果,在TableAdapter查询生成器执行查询窗口中返回结果,但在代码中失败,并在使用预览数据对话框时失败。
问题似乎出现在DateTime参数中。奇怪的是它只有在嵌入的选择语句中才会失败。应用于整个查询时,它工作正常。不幸的是我在嵌套部分需要它,但我总是得到“标准表达式中的数据类型不匹配”。如果我删除其他参数,并且将数据参数保留在嵌套查询中,则查询也有效。
使用:
SELECT Employee.FirstName, TimeCard.ID
FROM (((Employee INNER JOIN
MasterFilmUnit ON Employee.ID = MasterFilmUnit.ID) INNER JOIN
MasterDepartment ON Employee.ID = MasterDepartment.ID) LEFT OUTER JOIN
(SELECT ID, WorkDate, EmployeeID
FROM DailyTimeCard
WHERE (WorkDate = ?)) TimeCard ON TimeCard.EmployeeID = Employee.ID)
使用:
SELECT Employee.FirstName, TimeCard.ID
FROM (((Employee INNER JOIN
MasterFilmUnit ON Employee.ID = MasterFilmUnit.ID) INNER JOIN
MasterDepartment ON Employee.ID = MasterDepartment.ID) LEFT OUTER JOIN
(SELECT ID, WorkDate, EmployeeID
FROM DailyTimeCard
) TimeCard ON TimeCard.EmployeeID = Employee.ID)
WHERE Employee.ProjectID=? AND WorkDate = ?
不起作用:
SELECT Employee.FirstName, TimeCard.ID
FROM (((Employee INNER JOIN
MasterFilmUnit ON Employee.ID = MasterFilmUnit.ID) INNER JOIN
MasterDepartment ON Employee.ID = MasterDepartment.ID) LEFT OUTER JOIN
(SELECT ID, WorkDate, EmployeeID
FROM DailyTimeCard
WHERE WorkDate = ? ) TimeCard ON TimeCard.EmployeeID = Employee.ID)
WHERE Employee.ProjectID=?
修改
我已经能够通过嵌套查询的员工部分来获得所需的输出,因此没有where语句适用于整个查询。我现在正在运行,但同样的,我无法弄清楚为什么原来不起作用:
使用:
SELECT Employee.FirstName, TimeCard.ID
FROM ((((SELECT Employee.*
FROM Employee Employee_1
WHERE (ProjectID = ?)) Employee Left OUTER JOIN
MasterFilmUnit ON Employee.ID = MasterFilmUnit.ID) LEFT OUTER JOIN
MasterDepartment ON Employee.ID = MasterDepartment.ID) LEFT OUTER JOIN
(SELECT DailyTimeCard.*
FROM DailyTimeCard
WHERE (WorkDate = ?)) TimeCard ON TimeCard.EmployeeID = Employee.ID)
任何帮助将不胜感激。我很难过。
答案 0 :(得分:0)
?
参数占位符按照它们出现的顺序进行处理,因此此查询将期望参数1为WorkDate
,参数2为ProjectID
如果仍然无效,请尝试将?
参数标记包装在CDate()
和/或(可能)CInt()
中,以强制参数为正确的数据类型。< / p>