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 OriginalGriff 321
1 Sergey Alexandrovich Kryukov 286
2 RyanDev 75
3 PhilLenoir 70
4 nv3 60
0 Sergey Alexandrovich Kryukov 6,691
1 OriginalGriff 6,119
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
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