DataTable.Load()引发错误:表达式中未定义的函数'CountWeekDays'

时间:2013-06-28 13:04:28

标签: .net sql vb.net ms-access

我正在使用Access数据库并尝试加载DataTable对象但是收到了遇到的错误。我的查询在标准访问模块中调用名为“CountWeekDays”的公共函数,当通过Access本身运行时,返回正确的结果。为什么在通过.NET应用程序调用它时这不起作用?

 SELECT tbl1.ProjectID, tbl1.EntryDate AS StartDate, tbl2.EntryDate AS EndDate, 
(SELECT (ChecklistDayMax - ChecklistDayMin + 1) AS DaysAlotted FROM milestone_def WHERE MilestoneDefID = [@milestoneID]) AS DaysAlotted, 
(SELECT ProjectPriority FROM project_master WHERE ProjectID = tbl1.ProjectID) AS Priority,    
 IIF(Priority = 1, (SELECT BonusDaysFH FROM milestone_def WHERE MilestoneDefID = [@milestoneID]), 
 IIF(Priority = 2, (SELECT BonusDaysFM FROM milestone_def WHERE MilestoneDefID = [@milestoneID]), 
 IIF(Priority = 3, (SELECT BonusDaysFL FROM milestone_def WHERE MilestoneDefID = [@milestoneID])))) AS BonusDaysAllotted, 
 CountWeekDays(tbl1.EntryDate, tbl2.EntryDate) AS DaysRequired
 FROM checklist_entries AS tbl1 
 INNER JOIN checklist_entries AS tbl2 ON tbl1.ProjectID = tbl2.ProjectID
 WHERE tbl1.ChecklistDay = (SELECT ChecklistDayMin FROM milestone_def WHERE MilestoneDefID = [@milestoneID])
 AND tbl2.ChecklistDay = (SELECT ChecklistDayMax FROM milestone_def WHERE MileStoneDefID = [@milestoneID]);

1 个答案:

答案 0 :(得分:1)

只有在从Access本身运行查询时,才能在Access查询中使用用户定义的VBA函数。如果您将在.NET应用程序中运行查询,那么查询将只返回开始/结束日期,您的.NET代码将必须计算它们之间的工作日数。