Click here to Skip to main content
12,395,181 members (63,687 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB Access VB.NET
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..........
Posted 5-Feb-13 21:17pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
PunithaSabareeswari 6-Feb-13 5:28am
   
This won't display correctly... to kandarp

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100