Date Comparison in Access Database
How can I compare a day in an access database to a given day in C #? Date column in database is general date (day / month / year)
try
{
database = new OleDbConnection(connectionString);
database.Open();
date = 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;
}
+2
a source to share
1 answer
You will need a hash (#) after the date literal. You can also specify the culture when formatting the date to match the expected database or use a specific format string.
However, you are better off using parameters than inserting a value into the query. Then you do not need to worry about the date format to match the expected database.
+1
a source to share