I've just spent the last few hours trying do something which I thought would be very simple. I'm encountering a "Data type mismatch in criteria expression" error when I try to run a parameterized query with dates on an Access 2007 Database. The problem column in the Database is is of a "Date/Time" DataType.
In a simplified example -
dataCommand.CommandText "SELECT * FROM tblData WHERE IDate > #24/07/2013 16:54:51#"
This works. But as soon as I try to parametrize the date I encounter the error. So..
dataCommand.CommandText = "SELECT * FROM tblData WHERE IDate > @BackSearchDate"
....
dataCommand.Parameters.Add(new OleDbParameter("@BackSearchDate", backSearchDate))
Will encounter the error. I've tried to provide the backSearchDate variable in numerous ways. DateTime, strings of various formats etc do not work.
I found this page which would indicate it's a known bug - but I've not been able to get any of the workarounds on the page to work either. I'm pretty stumped.
Thanks in advance for any help.