Comparing date in access database
How can i compare the day in the access database to a given day in c#? The date column in the database is an general date(day/month/year)
try
{
database = new OleDbConnection(connectionString);
database.Open();
dat开发者_C百科e = DateTime.Now.ToShortDateString();
string queryString = "SELECT user_name,zivila.naziv "
+ "FROM (users LEFT JOIN obroki_save ON obroki_save.ID_uporabnika=users.ID)"
+ " LEFT JOIN zivila ON zivila.ID=obroki_save.ID_zivila "
+ " WHERE users.ID= " + a.ToString() + " AND obroki_save.datum=# " + date;
loadDataGrid(queryString);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
You need a hash (#) after the date literal also. You might also have to specify a culture when formatting the date to get it to match what the database expects, or use a specific format string.
However, you should rather use parameters than inserting the value in the query. Then you don't have to worry about getting the date format to match what the database might expect.
精彩评论