未定义的函数:MONTHNAME - OLEDB

时间:2017-09-29 02:36:36

标签: c# sql ms-access rdlc

我在RDLC报告中有这个功能。 我在Ms Access中构建了字符串(因为我很难直接写出来) 它适用于MS Access,它可以在我的PC上的vis studio中运行。 编译成EXE时也可以。

然而,在一台笔记本电脑上,它正在推出

  

表达式中未定义的函数MonthName

SELECT MonthName(Month(tblpack.cycledate)) AS MonthDate, Year(tblpack.cycledate) AS YearDate, Sum(tblpack.weeksinpack) AS SumOfweeksinpack, Month(tblpack.cycledate) AS MonthOrder
FROM tblpatient INNER JOIN tblpack ON tblpatient.patientid = tblpack.patientid
WHERE (((tblpack.iscommunity)=True) AND ((tblpatient.over5med)=True) AND ((tblpack.isrepat)=True) AND ((tblpack.cycledate) Between ? And ?) AND ((tblpack.packeduser) Is Not Null)) OR (((tblpack.iscommunity)=True) 
AND ((tblpatient.over5med)=True) AND ((tblpack.isconcession)=True) AND ((tblpack.cycledate) Between ? And ?) AND ((tblpack.packeduser) Is Not Null))
GROUP BY MonthName(Month(tblpack.cycledate)), Year(tblpack.cycledate), Month(tblpack.cycledate)
ORDER BY MonthName(Month(tblpack.cycledate)), Year(tblpack.cycledate)

任何帮助都会很棒。我无法理解为什么它在一台计算机上工作而不是另一台计算机,当字符串相同且连接也相同时!

Gangel

1 个答案:

答案 0 :(得分:1)

您不能将MonthName函数与ADO.NET一起使用,因为沙盒函数仅适用于在Access应用程序会话中运行的查询。 This article描述了与您的问题相关的访问行为:

  

自定义用户编写的VBA函数以及许多内置VBA   语言功能由嵌入在中的Microsoft Access执行   SQL查询。不幸的是Jet数据库可用的功能   引擎是有限的(当通过ADO,ADO.NET等执行时)

作为一种变通方法,您可以使用Format函数和MMMM格式字符串来显示完整的月份名称:

SELECT Format(tblpack.cycledate, 'MMMM') AS MonthDate,
       Year(tblpack.cycledate) AS YearDate, Sum(tblpack.weeksinpack) AS SumOfweeksinpack, 
       Month(tblpack.cycledate) AS MonthOrder
FROM tblpatient 
INNER JOIN tblpack ON tblpatient.patientid = tblpack.patientid
WHERE (((tblpack.iscommunity)=True) 
      AND ((tblpatient.over5med)=True) 
      AND ((tblpack.isrepat)=True) 
      AND ((tblpack.cycledate) Between ? And ?) 
      AND ((tblpack.packeduser) Is Not Null)) 
      OR (((tblpack.iscommunity)=True) 
      AND ((tblpatient.over5med)=True) 
      AND ((tblpack.isconcession)=True) 
      AND ((tblpack.cycledate) Between ? And ?) 
      AND ((tblpack.packeduser) Is Not Null))
GROUP BY Format(tblpack.cycledate, 'MMMM'), Year(tblpack.cycledate), Month(tblpack.cycledate)
ORDER BY Format(tblpack.cycledate, 'MMMM'), Year(tblpack.cycledate)

参考文献:

How to configure Jet 4.0 to prevent unsafe functions from running in Access 2003

month name from date field in c#.net from access database