Click here to Skip to main content
11,930,449 members (62,859 online)
Rate this:
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);
                    empleave.Date = dtFrom.SelectedDate;

Please help me, what is the wrong in this source and give you suggestions
Posted 18-Feb-12 23:18pm

1 solution

Rate this: bad
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?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 19 Feb 2012
Copyright © CodeProject, 1999-2015
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