来自外部应用程序(C#)的Access数据库中日期字段的月份名称 [英] Month name of date field in Access database from external application (C#)
问题描述
我想在C#的运行时填充一个下拉列表.我在Access 2003数据库中有一个日期/时间"字段(例如2000年5月1日).我想在运行时在下拉列表中输入月份名称(即一月,二月...).
SELECT DISTINCT MonthName(Month(DATE_OF_BOOKING)) AS MNTH
FROM TRAVEL_DETAILS WHERE YEAR(DATE_OF_BOOKING)='2008'
当我直接从Access运行它时,上面的查询工作正常,
但是当我试图从C#中的OledbCommand
对象运行它时,它说
表达式中未定义的函数'MonthName'.
社交msdn中的文本如何配置Jet 4.0以防止在Access 2003中运行不安全的功能. >
使用Format()方法.
SELECT DISTINCT format(DATE_OF_BOOKING,'MMMM')
AS MNTH FROM TRAVEL_DETAILS WHERE YEAR(DATE_OF_BOOKING)='2008'
I want to populate a drop down list at runtime in C#. I have a Date/Time field (e.g., 01/05/2000) in an Access 2003 database. I want to have the month name (i.e. January, February, ...) in the drop down list at runtime.
SELECT DISTINCT MonthName(Month(DATE_OF_BOOKING)) AS MNTH
FROM TRAVEL_DETAILS WHERE YEAR(DATE_OF_BOOKING)='2008'
The above query works fine while I'm running it from Access directly,
but when I'm trying to run it from an OledbCommand
object in C# it says
Undefined function 'MonthName' in expression.
Text from social 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.
EDIT: Use Format() method.
SELECT DISTINCT format(DATE_OF_BOOKING,'MMMM')
AS MNTH FROM TRAVEL_DETAILS WHERE YEAR(DATE_OF_BOOKING)='2008'
这篇关于来自外部应用程序(C#)的Access数据库中日期字段的月份名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!