来自外部应用程序的Access数据库中的日期字段的月份名称(C#)

前端之家收集整理的这篇文章主要介绍了来自外部应用程序的Access数据库中的日期字段的月份名称(C#)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在C#中在运行时填充下拉列表.我在Access 2003数据库中有一个日期/时间字段(例如,01/05/2000).我希望在运行时的下拉列表中有月份名称(即1月,2月,…).
SELECT DISTINCT MonthName(Month(DATE_OF_BOOKING)) AS MNTH 
    FROM TRAVEL_DETAILS WHERE YEAR(DATE_OF_BOOKING)='2008'

上面的查询工作正常,我直接从Access运行它,
但是,当我试图从C#中的OledbCommand对象运行它时,它说

Undefined function ‘MonthName’ in expression.

解决方法

来自社交msdn thread文字

Custom user-written VBA functions as
well as many built-in VBA language
functions are executed by Microsoft
Access when embedded in a sql query.
Unfortunately the functions available
to the Jet database engine are limited
(when executed via ADO,ADO.NET,
etc.). You can find a list of those
available in the following MS KB
article:

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

编辑:使用Format()方法.

SELECT DISTINCT  format(DATE_OF_BOOKING,'MMMM') 
   AS MNTH FROM TRAVEL_DETAILS WHERE YEAR(DATE_OF_BOOKING)='2008'

猜你在找的MsSQL相关文章