VB Express查询中的日期条件 [英] date criteria in VB Express query

查看:82
本文介绍了VB Express查询中的日期条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Microsoft Access中,我可以编写包含以下条件的查询:


日期() - 7和日期()


从上一周内的表中检索记录。


我正在尝试用VB.NET编写一个程序(2005 Express

版)。但我总是得到消息说Jet数据库引擎

不能识别语法(我假设的Date函数)。我已经尝试使用Now()并且它只能单独工作。我似乎添加或者

减去它的时间。


什么是最好的语法?我在查询设计器中工作。


谢谢!

Daniel

解决方案

Daniel,


你能告诉我们查询(这是一个SQL程序),比我们得到的更好

更好你的问题。


我通过实例不知道声明之间


Cor


丹尼尔 < da ********** @ gmail.comschreef在bericht

新闻:11 ******************** **@i42g2000cwa.googlegr oups.com ...


在Microsoft Access中,我可以编写包含以下条件的查询:


日期() - 7和日期()


从表格中检索上周内的记录。


我正在尝试用VB.NET编写一个程序(2005 Express

Edition)。但我总是得到消息说Jet数据库引擎

不能识别语法(我假设的Date函数)。我已经尝试使用Now()并且它只能单独工作。我似乎添加或者

减去它的时间。


什么是最好的语法?我在查询设计器中工作。


谢谢!

Daniel



好吧,在Access中我会写这个查询来得到我想要的结果:

SELECT tblDates。* FROM tblDates

WHERE tblDates .entry_date BETWEEN Date() - 7和Date();


这使用内置的Date()函数来检索要拉的当前

系统日期tblDates中的所有内容在过去7天内有一个

entry_date的表。


如何在查询设计器中用VB 2005 Express编写此查询?我使用链接到Access 2003

(Microsoft Jet 4.0)数据库的OLEDB连接对象来获取
。问题似乎是当

TableAdapter对象试图查询Jet数据库引擎时,Jet引擎

会返回一个错误,它不知道日期是什么()函数是。我认为适配器对象的重点是接受你的查询

并将其翻译成与数据库类型兼容的语法

正在查询。但相反,它似乎将我的查询的字面值直接传递给Jet。


非常感谢!


10月12日晚上11:43,Cor Ligthert [MVP] < notmyfirstn ... @ planet.nl>

写道:


Daniel,


你能告诉我们查询(这是一个SQL程序),比我们得到的更好吗

你的问题更好。


我做的实例不知道声明之间


Cor


Daniel < danielcre ... @ gmail.comschreef in berichtnews:11 ********************** @ i42g2000cwa.g ooglegroups.com ...


在Microsoft Access中,我可以编写包含以下条件的查询:


Date()之间 - 7 And Date()


从表格中检索上周内的记录。


我正在尝试编写一个在VB.NET(2005 Express

Edition)中执行此操作的过程。但我总是得到消息说Jet数据库引擎

不能识别语法(我假设的Date函数)。我已经尝试使用Now()并且它只能单独工作。我似乎在增加或者减去

从中扣除时间。


什么是最好的语法?我在查询设计器中工作。


谢谢!

Daniel


如何使用以下内容作为您的查询:


< pseudocode>


SQLstring =" SELECT tblDates 。* FROM tblDates WHERE tblDates.entry_date


> =" &安培; DateAdd(DateInterval.Day,-7,Now())。ToString()& "和tblDates.entry_date< " &安培; now()。tostring()



< / pseudocode>


谢谢,


Seth Rowe

Daniel写道:


好​​吧,在Access中我会写这个查询来得到我想要的结果:


SELECT tblDates。* FROM tblDates

WHERE tblDates.entry_date BETWEEN Date() - 7和Date();


这使用内置的Date()函数,该函数检索当前的

系统日期以从tblDates中提取所有内容。在过去7天内有一个

entry_date的表。


如何在查询设计器中用VB 2005 Express编写此查询?我使用链接到Access 2003

(Microsoft Jet 4.0)数据库的OLEDB连接对象来获取
。问题似乎是当

TableAdapter对象试图查询Jet数据库引擎时,Jet引擎

会返回一个错误,它不知道日期是什么()函数是。我认为适配器对象的重点是接受你的查询

并将其翻译成与数据库类型兼容的语法

正在查询。但相反,它似乎将我的查询的字面值直接传递给Jet。


非常感谢!


10月12日晚上11:43,Cor Ligthert [MVP] < notmyfirstn ... @ planet.nl>

写道:


Daniel,


你能告诉我们查询(这是一个SQL程序),比我们得到的更好吗

你的问题更好。


我做的实例不知道声明之间


Cor


Daniel < danielcre ... @ gmail.comschreef in berichtnews:11 ********************** @ i42g2000cwa.g ooglegroups.com ...


在Microsoft Access中,我可以编写包含以下条件的查询:


Date()之间 - 7 And Date()


从表格中检索上周内的记录。


我正在尝试编写一个在VB.NET(2005 Express

Edition)中执行此操作的过程。但我总是得到消息说Jet数据库引擎

不能识别语法(我假设的Date函数)。我已经尝试使用Now()并且它只能单独工作。我似乎在增加或者减去

从中扣除时间。


什么是最好的语法?我在查询设计器中工作。


谢谢!

Daniel


In Microsoft Access I can write a query that includes the criteria:

Between Date()-7 And Date()

to retrieve the records from a table that fall within the last week.

I''m trying to write a procedure to do this in VB.NET (2005 Express
Edition). But I always get the message that the Jet database engine
does not recognize the syntax (of the Date function I assume). I''ve
also tried Now() and it works but only by itself. I seem to add or
subtract time from it.

What''s the best syntax to use? I''m working in the Query Designer.

Thanks!
Daniel

解决方案

Daniel,

Can you show us the query (is it an SQL procedure), than we get probably
better at your problem.

I do by instance not know the statement "Between"

Cor

"Daniel" <da**********@gmail.comschreef in bericht
news:11**********************@i42g2000cwa.googlegr oups.com...

In Microsoft Access I can write a query that includes the criteria:

Between Date()-7 And Date()

to retrieve the records from a table that fall within the last week.

I''m trying to write a procedure to do this in VB.NET (2005 Express
Edition). But I always get the message that the Jet database engine
does not recognize the syntax (of the Date function I assume). I''ve
also tried Now() and it works but only by itself. I seem to add or
subtract time from it.

What''s the best syntax to use? I''m working in the Query Designer.

Thanks!
Daniel



Well, in Access I would write this query to get the results I want:

SELECT tblDates.* FROM tblDates
WHERE tblDates.entry_date BETWEEN Date()-7 And Date();

This uses the built in Date() function which retrieves the current
system date to pull everything from the "tblDates" table that has an
entry_date within the last 7 days.

How do I write this query in VB 2005 Express in the Query Designer? I
am working with an OLEDB connection object linked to my Access 2003
(Microsoft Jet 4.0) database. The problem seems to be that when the
TableAdapter object tries to query the Jet db engine, the Jet engine
returns an error that it doesn''t know what the Date() function is. I
thought the whole point of the adapter object was to take your query
and translate it into syntax compatible with the type of database you
are querying. But instead, it seem to be passing the literal value of
my query directly to Jet.

Thanks so much!

On Oct 12, 11:43 pm, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:

Daniel,

Can you show us the query (is it an SQL procedure), than we get probably
better at your problem.

I do by instance not know the statement "Between"

Cor

"Daniel" <danielcre...@gmail.comschreef in berichtnews:11**********************@i42g2000cwa.g ooglegroups.com...

In Microsoft Access I can write a query that includes the criteria:

Between Date()-7 And Date()

to retrieve the records from a table that fall within the last week.

I''m trying to write a procedure to do this in VB.NET (2005 Express
Edition). But I always get the message that the Jet database engine
does not recognize the syntax (of the Date function I assume). I''ve
also tried Now() and it works but only by itself. I seem to add or
subtract time from it.

What''s the best syntax to use? I''m working in the Query Designer.

Thanks!
Daniel


How about using the following as you''re query:

<pseudocode>

SQLstring = "SELECT tblDates.* FROM tblDates WHERE tblDates.entry_date

>=" & DateAdd(DateInterval.Day, -7, Now()).ToString() & " and tblDates.entry_date < " & now().tostring()

</pseudocode>

Thanks,

Seth Rowe
Daniel wrote:

Well, in Access I would write this query to get the results I want:

SELECT tblDates.* FROM tblDates
WHERE tblDates.entry_date BETWEEN Date()-7 And Date();

This uses the built in Date() function which retrieves the current
system date to pull everything from the "tblDates" table that has an
entry_date within the last 7 days.

How do I write this query in VB 2005 Express in the Query Designer? I
am working with an OLEDB connection object linked to my Access 2003
(Microsoft Jet 4.0) database. The problem seems to be that when the
TableAdapter object tries to query the Jet db engine, the Jet engine
returns an error that it doesn''t know what the Date() function is. I
thought the whole point of the adapter object was to take your query
and translate it into syntax compatible with the type of database you
are querying. But instead, it seem to be passing the literal value of
my query directly to Jet.

Thanks so much!

On Oct 12, 11:43 pm, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:

Daniel,

Can you show us the query (is it an SQL procedure), than we get probably
better at your problem.

I do by instance not know the statement "Between"

Cor

"Daniel" <danielcre...@gmail.comschreef in berichtnews:11**********************@i42g2000cwa.g ooglegroups.com...

In Microsoft Access I can write a query that includes the criteria:

Between Date()-7 And Date()

to retrieve the records from a table that fall within the last week.

I''m trying to write a procedure to do this in VB.NET (2005 Express
Edition). But I always get the message that the Jet database engine
does not recognize the syntax (of the Date function I assume). I''ve
also tried Now() and it works but only by itself. I seem to add or
subtract time from it.

What''s the best syntax to use? I''m working in the Query Designer.

Thanks!
Daniel


这篇关于VB Express查询中的日期条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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