Select statement in with MS Access and C# 1.1

Hey guys

I have a MS Access DB with enrties in. I have 2 columns withing a table… called “Start_Date” and “End_Date”

Now wat i need to do is select all rows where the current date is between the start and end dates. How wud i do this?

At the moment i have the following:
“select * from tblName where '” + DateTime.Now + “’ between [Start_Date] and [End_Date]”

But this does not work. Both the columns are of “Date/Time” data type.

This is the error i am getting: Data type mismatch in criteria expression.

Please help.


I’m not sure but here is a try

… WHERE Start_Date < @DateTimeNow AND End_Date > @DateTimeNow

myCommand.Parameters.Add(“@DateTimeNow”, DateTime.Now);

Hey pufa… thanks a lot for the reply. I will try that when i get a chance and report back…

Thanks again

Hey pufa

I tried ur example, but it still didnt work. It comes back with the same error.

I dnt no wat this things problem is. :frowning:

I think the Parameter is passing as a string, not DateTime.

try this first

… WHERE Start_Date < #" + DateTimeNow + “# AND End_Date > #” + @DateTimeNow + “#”

if it works than that’s the problem, Date types must be enclosed in “#”.

another way might be to specify the DataType of the Parameter.

… WHERE Start_Date < @DateTimeNow AND End_Date > @DateTimeNow

myCommand.Parameters.Add(“@DateTimeNow”, OleDbType.DBDate).Value = DateTime.Now;