Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL LINQ
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.
 
 
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 18-Feb-12 22:18pm
P.T.R.K997

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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?
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 404
1 Nirav Prabtani 268
2 _Amy 230
3 CHill60 170
4 Sergey Alexandrovich Kryukov 166
0 OriginalGriff 8,004
1 Sergey Alexandrovich Kryukov 7,017
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 19 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100