Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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 at 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
0 Maciej Los 350
1 OriginalGriff 283
2 Nguyen.H.H.Dang 230
3 Sergey Alexandrovich Kryukov 230
4 Peter Leow 195


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