gpt4 book ai didi

c# - 如何修复 "SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value."

转载 作者:太空狗 更新时间:2023-10-29 17:35:07 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com