Reputation: 320
I have to datetimepickers FromDate and ToDate, and want to do select data between to dates, I have written the query
select * from tbl where pDate>='" + dtpFrom.value + "'and pDate<='" + dtpTo.value + "'");
This query giving error
Data type mismatch in criteria expression
But datatype is Date/Time in ms access table.
Upvotes: 1
Views: 3142
Reputation: 98750
Looks like you try to put single quotes for your DateTime
values. #
for dates and '
for strings but they required for literal SQL queries.
If you use parameterize queries, you will not need them.
using(var con = new OleDbConnection(conString))
using(var cmd = con.CreateCommand())
{
cmd.CommandText = "select * from tbl where pDate >= ? and pDate <= ?"
cmd.Parameters.AddWithValue("?", dtpFrom.Value);
cmd.Parameters.AddWithValue("?", dtpTo.Value);
...
...
}
Upvotes: 2