saumya vishnoi
saumya vishnoi

Reputation: 137

Date comparison in where condition in C# with oledb database

I have to take 2 values from DateTimePicker and then compare their values with that in database.

Code:

string dt_start = dateTimePicker1.Value.ToShortDateString();
string dt_end = dateTimePicker2.Value.ToShortDateString();
string mySelectQuery = "Select * from " + out_table + " WHERE [Date] Between " + dt_start + " and " + dt_end + " ";

It is not showing any error, but I am not getting output values.

Upvotes: 3

Views: 4930

Answers (2)

Igor Turman
Igor Turman

Reputation: 2205

Access uses # for dates. This should work:

string mySelectQuery = "Select * from " + out_table + " WHERE [Date] Between #" + dt_start + "# and #" + dt_end + "#";

Upvotes: 3

Vikram
Vikram

Reputation: 8333

try the following select statement:

string mySelectQuery = "Select * from " + out_table + " WHERE [Date] Between '" + dt_start + "' and '" + dt_end + "' ";

Upvotes: 0

Related Questions