DataTable.Load() Throws Error: Undefined function

2020-04-17 07:13发布

问题:

I'm using an Access database and trying to load a DataTable object but am receiving the subjected error. My query calls a public function named 'CountWeekDays' within a standard access module and when run through Access itself, returns the proper results just fine. Why would this not work when calling it through a .NET application?

 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:

User-defined VBA functions can be used in Access queries only when the query is run from within Access itself. If you will be running the query from within a .NET application then the query will have to return just the start/end dates and your .NET code will have to calculate the number of weekdays between them.