I have a problem using the calender control .. I am getting the date in a textbox… and I have to insert this into the database .. using asp.net with c#
In my web application the field property is set to datetime and in the table the column’s datatype is date..
How can I do this??
The error I am getting is:
The conversion of a varchar data type to a datetime data type resulted
in an out-of-range value. The statement has been terminated.
Could anyone help me in this regard?
Thanks in advance
It sounds like you’re trying to insert it as a string, which is a generally bad idea. You should use parameterized SQL and set the value as a parameter, still as a .NET
DateTime. See the docs forSqlCommand.Parametersfor an example of parameterized SQL. You should always keep data in its natural type for as long as possible.Of course, it’s then still possible that you’ll get this error if you try to insert a
DateTimevalue which is out of the range that SQL can store. In particular, I believe SQL has a lower limit of 1753 as the year. If your value isDateTime.MinValuefor some reason (January 1st, 1AD) then you’d still get this problem. Have you added diagnostics for the value you’re trying to insert?