Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Statement in VB.net

Status
Not open for further replies.

mkohl

Programmer
Feb 22, 2005
82
US
I am having a problem. My records are not populating in the datagrid.

Query = "select * from JobsOnHold where [Date] between '6/4/2006%' and '6/10/2006%'"

I think the problem is that the data field has a time stamp in the field. example: m/d/yyyy 10:10:21 am

database info: microsoft access
IDE: .net
Language: vb.net
 
Try
Query = "select * from JobsOnHold where [Date] between '6/4/2006' and '6/11/2006'"


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
As we are in the JetSQL forum:
Query = "SELECT * FROM JobsOnHold WHERE [Date] Between #2006-06-04 00:00:00# And #2006-06-10 23:59:59#"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, I think my problem might have been that I declared date as text in the table.

After changing the date from text to date and time, I ran this query:
"select * from JobsOnHold where [Date] between #6/4/2006# and #6/10/2006#"

and it works.

Thanks guys.
 
mkohl,

Looking at PHV's example, you'll notice that he added 23:59:59 to the end date. Without the time component being 23 hours, 59 minutes, and 59 seconds, the only records you will get for 6/10/2006 are those that occur at midnight (time 00:00:00). I mention this so that you can (hopefully) avoid data problems. I urge you to double check your data to make sure it is returning what you expect.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top