I want to compare a DateTime date & time in a GridView to a smallDateTime date & time in a database table. I'm not sure what goes wrong, but I get the error message "incorrect syntax near 'whatever time'" every time. An example: A DateTime datumStartTid could be '2010-07-25 19:00' to which I add ':00' and the smallDateTime in the database table looks like this '2010-07-25 19:00:00'.
What did I do wrong? Maybe the error is somewhere else but after trying different approaches this is what I've come down to. Some of my code below with an error message after trying to compare the example above.
DateTime datumStartTid = Convert.ToDateTime(datum + " " + starttid + ":00");
SqlConnection .........
string sql = "DELETE FROM Tillfalle WHERE Tillfalle.datumStartTid = " + datumStartTid;
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader dr = comm.ExecuteReader(); //Incorrect syntax near '19'.
dr.Close();