First off, make it a habit to put objects that eat resources such as SqlConnection, SqlCommand and SqlDataAdapter within a
[
^]using Statement to ensure that objects will be properly disposed and closed after they are used.
Second, "DO NOT" append the value of your input fields to your SQL query as it can lead you to SQL Injection attack. Use parameterize query instead.See:
Protect Your Data: Prevent SQL Injection[
^]
Now back to your original question. Comparing string date is very straight-forward like this:
if (Convert.ToDateTime(date).Equals(DateTime.Now())){
}
You need to compare a
DateTime
object and not a
string
. You just need to make sure that the value of the date from your Label is a valid datetime or else use
DateTime.TryParse()
instead of
Convert.ToDateTime()