Click here to Skip to main content
15,899,020 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.


What I have tried:

cmd.Parameters.AddWithValue("@dob", SqlDbType.DateTime).Value = dateTimePicker1.Value.Date;
              cmd.Parameters.AddWithValue("@dob", Convert.ToDateTime(txtdob.Text));
Posted
Updated 3-Mar-19 23:13pm

You are trying to use an invalid date. Use your debugger to see exactly what value is the incorrect one.
 
Share this answer
 
We can't help you with that - we have no access to the value you are passing to SQL (and I assume that you tried both of those code lines separately, rather than together) and that is very likely to be fundamental to the problem.

If the date you are sending is before 1753 and that's what you are expecting, then convert to DATETIME2 instead of DATETIME as that supports 0001/01/01 to 9999/12/31 instead of 1753/01/01 to 9999/12/31

Use the debugger to find out exactly what you are passing - we can't do that for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900