I am working on c# project and using winform.
Here the problem is the query was working previously but now it is not working
Here the todaydate is a datetimePicker which is set to short date format
and my datatype of column is smalldatetime the error i am getting is
The conversion of a nvarchar data type to a
smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
if i have two date time picker one for date and second for time then how can i insert? please can you guide me
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 theDateTimevalue it provides:… or create the parameter first with a specific type (
SqlDbType.SmallDateTime), then set the value usingtodaydate.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.
DateTimein 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!