使用Linq to SQL插入/更新DateTime字段 [英] Insert/Update DateTime field using Linq to SQL

查看:82
本文介绍了使用Linq to SQL插入/更新DateTime字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试使用Linq to SQL插入/更新datetime字段.它将显示以下错误

SqlDateTime溢出.必须介于1/1/1753 12:00:00 AM和12/31/9999 11:59:59 PM之间.

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

推荐答案

可能是因为您要添加天数并插入循环中.您需要设置一个断点并查看tdDays.Days的值-您添加的值到底有多大?
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?


这篇关于使用Linq to SQL插入/更新DateTime字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆