I am using vb.net and ms access 2003 as backend. I am not getting any records in my result when I'm using the sql query shown below. I'm trying to find records with a date lower (or coming before) the current date.
Dim Sql, CurrentDate as String
Dim TrDate as Date
Dim DataVal As Integer
TrDate=DateTime.Now
CurrentDate=Format(TrDate, "dd/MM/yyyy hh:mm:ss tt")
Sql="Select count(*) from Table1 where InvDate<=#" & CurrentDate & "#"
IF DBConOpen()=True
cmdOledb.CommandText = sql
cmdOledb.CommandType = CommandType.Text
cmdOledb.Connection = ConOledb
DataVal = cmdOledb.ExecuteScalar
msgbox(DataVal)
End IF
For example if my current date is 01/09/2012 or 02/09/2012 or .. 12/09/2012 and the date in database is 01/09/2012 or 02/09/2012 or .. 12/09/2012. I should get the respective record count. But in this case im getting 0 records.
But if my current date is 01/09/2012 or 02/09/2012 or .. 12/09/2012 and the date in database is 20/08/2012 or 15/06/2012 or .. 30/05/2012. I am getting the correct record count.
The date format I defined in MS access table is 'General Date'. Is anyone able to spot what is wrong?