Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am trying to insert/update the datetime field using Linq to SQL. It will show the following error

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

C#
TimeSpan tsDays = dtTo.SelectedDate.Subtract(dtFrom.SelectedDate);
                EmployeeLeave empleave = new EmployeeLeave();
                empleave.EmployeeID = Convert.ToInt32(cmbEmployee.SelectedItem.Value);
                empleave.LeaveTypeName = cmbLeaveType.SelectedItem.Value;
                empleave.IsHalfDay = (chkHalfDay.Checked) ? true : false;
                empleave.IsFormal = (chkFormal.Checked) ? true : false;
                empleave.Reason = txtReason.Text.Trim();
                if (tsDays.Days > 0)
                {
                    for (int i = 0; i < tsDays.Days; i++)
                    {
                        empleave.Date =dtFrom.SelectedDate.AddDays(i);
                        pdc.EmployeeLeaves.InsertOnSubmit(empleave);
                    }

                }
                else
                {
                    empleave.Date = dtFrom.SelectedDate;
                    pdc.EmployeeLeaves.InsertOnSubmit(empleave);
                }
                pdc.SubmitChanges();


Please help me, what is the wrong in this source and give you suggestions
Posted

1 solution

Probably, the problem is that you are adding days and inserting in a loop. You need to set a breakpoint and look at the value of tdDays.Days - just how big is the value you are adding?
 
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