作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
我的代码是这样的:
using (var contxt = new realtydbEntities())
{
var status = GetStatus();
var repIssue = new RepairIssue()
{
CreaterId = AuthorId,
RepairItemDesc = this.txtDescription.Text,
CreateDate = DateTime.Now,//here's the problem
RepairIssueStatu = status
};
contxt.AddObject("RepairIssues", repIssue);
contxt.SaveChanges();
}
CreateDate 属性映射到类型为 smalldatetime 的列。
如何让这段代码运行起来?
最佳答案
我遇到了同样的异常,但这是因为一个不可为空的日期时间属性采用了最小日期时间值。那不是 smalldatetime 在 DB,但 C# 的最小日期时间超过了 SQL 的最小日期时间的限制。解决方案很明显,正确设置日期时间。顺便说一句,代码不是我的,这就是我不知道该属性的原因:)
关于c# - 如何修复 "SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10495557/
我是一名优秀的程序员,十分优秀!