Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in inserting statement when inserting

Tags:

c#

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

like image 962
shariq_khan Avatar asked Nov 19 '25 01:11

shariq_khan


1 Answers

AddWithValue determines the datatype of the parameter from the value you pass.

In your case you are passing a string and thus the parameter is passed to the database as a string not as a datetime expected by the database

you should change that line

cmd.Parameters.AddWithValue("@today", todaydate.Value);
like image 113
Steve Avatar answered Nov 21 '25 15:11

Steve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!