views:

65

answers:

1

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();
           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;
       }
+1  A: 

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.

Guffa
How do i use parameters ?
Simon
@Simon: The command object has a `Paramaters` collection where you add parameters and their values, then you can use the parameters in the query.
Guffa