GETDATE()引发异常 [英] GETDATE() throwing exception

查看:101
本文介绍了GETDATE()引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的应用程序,其中使用 MSAccess 作为数据库. 当我尝试使用以下查询检索数据时-我收到异常未定义函数GETDATE()

I am creating a simple application where i am using MSAccess as database. When i am trying to retrieve the data using below query - i am getting exception undefined function GETDATE()

select *
from tempdata
where dateissue  between DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) - 0 , 0) 
and  DATEADD(MM,         DATEDIFF(MM, 0, GETDATE()) + 1, - 1 )

我们不能在C#代码中使用sql内置方法吗?如果可以,我该如何解决这个问题

can't we use the sql inbuilt methods inside c# code ?? if so how do i solve this problem

推荐答案

现在您已经解决了第一个问题(Access SQL中没有GETDATE()函数),您发现了另一个问题.

Now that you moved past the first problem (there is no GETDATE() function in Access SQL), you have discovered another problem.

DateAdd函数需要字符串表达式,它是您要添加的时间间隔" 作为其第一个参数 Interval .但是,您给它的却是MM:

The DateAdd Function requires a "String expression that is the interval of time you want to add" as its first argument, Interval. But you're giving it MM instead:

DATEADD(MM, DATEDIFF(MM, 0, DATE()) - 0 , 0)

我不明白您要添加的时间间隔.如果要增加分钟,请使用...

I don't understand what interval you're trying to add. If you want to add minutes, use ...

DateAdd('n', ...

如果要增加月份,请使用...

If you want to add months, use ...

DateAdd('m', ...

如果要添加天数,请使用...

If you want to add days, use ...

DateAdd('d', ...

注意DateDiff()还需要一个 Interval 字符串参数,并且允许的值与DateAdd()的值相同.

Note DateDiff() also expects an Interval string argument and the allowable values are the same as those for DateAdd().

这篇关于GETDATE()引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆