You're currently passing in the text value, which means something else is having to then parse it as a date. Don't do that. Given that you've got a DateTimePicker
, you should just use the DateTime
value it provides:
cmd.Parameters.AddWithValue("@today", todaydate.Value);
... or create the parameter first with a specific type (SqlDbType.SmallDateTime
), then set the value using todaydate.Value
. The important point is to avoid the string conversion.
Wherever possible, you should avoid converting values into text. Keep them in their "natural" form (e.g. DateTime
in this case) for as much of the time as possible: on input, parse into the natural form, and if you can avoid ever converting to a string, do so!