I am working on an old software that uses a .mdb database.
I have succeeded in setting up a connection to the database and i can run sql queries just fine when it comes to preprogrammed queries like this one :
SELECT COUNT(*) AS test FROM shifts WHERE EmpId = '2' AND DateOpen <= '3/28/2007'
Moving on, i replaced the 2 with an expression depending on the user selection like so
Employees(employe.SelectedIndex)
This worked fine too.
Now, when i tried to replace the date with startDate.Value.ToShortDateString i started facing many conversion problems and i finally had something that worked so my where clause became like this :
WHERE EmpId = '" & Employees(employe.SelectedIndex) & "' AND DateDiff('d', DateOpen, '" & endDate.Value.ToShortDateString & "') <= 0
Now i chose the same date that was in the query above, the query runs with no problems but surprisingly i got a null result, which doesn’t make any sense to me because the query with the values already there returned a count of 2.
I used some debugging output to make sure the query is properly being generated and i got the same query as above when i select the date.
If you have any idea why this is not working or have any hints on the proper way to do it, i would appreciate all your input.
Thanks in advance
I ended up using BETWEEN in the query, and with params the query works like a charm!