Compare dates
-
Hi.i am trying to compare today 's date with a date from database.if it found like today 's date is available from database it should return something like eventname.here is my code string Today = DateTime.Now.ToShortTimeString().ToString(); SqlCommand cmdDisplay = new SqlCommand(); cmdDisplay.Connection = conn; cmdDisplay.CommandText = "SELECT EventName FROM Events WHERE EventDate = '"+ Today + "'"; SqlDataReader dr = cmdDisplay.ExecuteReader(); while(dr.Read()) { string EDate; EDate = dr["EventDate"].ToString(); if(EDate == Today) { txtEventName.Text =dr["EventName"].ToString(); } }
-
Hi.i am trying to compare today 's date with a date from database.if it found like today 's date is available from database it should return something like eventname.here is my code string Today = DateTime.Now.ToShortTimeString().ToString(); SqlCommand cmdDisplay = new SqlCommand(); cmdDisplay.Connection = conn; cmdDisplay.CommandText = "SELECT EventName FROM Events WHERE EventDate = '"+ Today + "'"; SqlDataReader dr = cmdDisplay.ExecuteReader(); while(dr.Read()) { string EDate; EDate = dr["EventDate"].ToString(); if(EDate == Today) { txtEventName.Text =dr["EventName"].ToString(); } }
You're storing dates as strings in the ShortTimeString format ? That's a time, not a date. And, it's an inefficient way to store them. And it's redundant - you ask for only for values with a specific time, and then you check to make sure your database is not lying to you ? I don't see a question here - what is the problem ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog