gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:41:42 28 4
gpt4 key购买 nike

我想在运行时用 C# 填充下拉列表。我在 Access 2003 数据库中有一个日期/时间字段(例如 01/05/2000)。我想在运行时的下拉列表中包含月份名称(即一月、二月……)。

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'

关于c# - 来自外部应用程序 (C#) 的 Access 数据库中日期字段的月份名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4720788/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com