在MS Access 2003数据库中的两个日期查询问题之间 [英] Between Two Dates Query Problem in MS Access 2003 Data Base

查看:86
本文介绍了在MS Access 2003数据库中的两个日期查询问题之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2008和MS Access 2003数据库中使用C#来开发Windows应用程序

现在我正在构建一个SQL查询来获取ACCEss数据库中两个日期之间的记录。但问题是我没有得到正确的结果。

我正在使用以下查询:



表格字段是日期时间。



sql =选择*来自TABLE,其中#04/04/2011之间的日期字段#

和#09/05/2011#;

im使用dataadapter和数据集来填充记录。

但此查询显示结果直到05/09/2011而不是09/05/2011。

我有尝试搜索谷歌,但没有找到精确的解决方案...

请帮助......紧急..........

解决方案

您可以在第一个datetime参数中看到,因为04/04看起来是正确的,但也是错误的。因此,由于日期的格式化,您在日期时间方面遇到问题。您应该使用:

格式(YourDateParam,yyyy / MM / dd hh:mm:ss tt)

访问需要一个明确的日期。

您可能也想删除时间元素。

-OR-

更好地使用参数化查询 [ ^ ]因此它将自动格式化为正确的日期时间。



祝你好运,

OI


使用日期对象和放大器;传递给它查询它会工作正常



日期开始= 日期(); 
Date End = new Date();
sql = 选择* From TABLE其中datefield之间的区域' + start + '
和'
+ End + ';







将有效细


I m using C# in VS2008 and MS Access 2003 Data Base to develop the windows application
Now i am building a SQL query to get record between two dates form ACCEss database. but problem is that i m not getting proper result.
I am using following query :

the table field is datetime.

sql="Select * From TABLE where datefield between #04/04/2011#
and #09/05/2011#";
i m using dataadapter and dataset to fill records.
but this query show result till 05/09/2011 instead of 09/05/2011.
I have try to search google but no precise solution found...
please help..its urgent..........

解决方案

AS you can see in your first datetime parameter because 04/04 is the same it seems correct but is wrong as well. So you are having issues with the datetime due to the formatting of the date. You should use:
Format(YourDateParam, "yyyy/MM/dd hh:mm:ss tt")
Access needs an unambiguous date.
You might like to remove the time element as well.
-OR-
better use parameterized queries[^] so it will be automatically formatted to the proper datetime.

Good luck,
OI


use Date object & pass it to query it will work fine

Date start =new Date();
Date End =new Date();
sql="Select * From TABLE where datefield between '"+start+"' 
and '"+End+"'";




will work fine


这篇关于在MS Access 2003数据库中的两个日期查询问题之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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