SqlException:更改 datetime2 数据类型的日期时间总线会导致值超出范围。该声明已终止

SqlException: Changing a datetime bus of the datetime2 data type resulted in an out-of-range value. The statement was terminated

提问人:melike aslan 提问时间:5/15/2023 最后编辑:marc_smelike aslan 更新时间:5/15/2023 访问量:33

问:

调用时,我收到此错误:_tld.SaveChanges();

SqlException:更改 datetime2 数据类型的日期时间总线会导致值超出范围。该声明已终止。

我的项目使用实体框架数据库优先和 SQL Server。这个问题的解决方案是什么?

这是我的代码,我在其中得到这个异常:

public static Result SavePendingTransactionsData(transaction[] model)
{
    Authorize authorize = new Authorize();

    using (TechLogisticsEntities _tld = new TechLogisticsEntities())
    {
        try
        {
            foreach (var item in model)
            {
                L_ROD_AsTwentyFourTransaction asTwentyFourTransaction = new L_ROD_AsTwentyFourTransaction();
                asTwentyFourTransaction.TransactionNumber = item.transactionNumber;
                asTwentyFourTransaction.TransactionType = item.transactionType;
                asTwentyFourTransaction.TransactionDate = item.entryTransactionDate;
                asTwentyFourTransaction.VehiclePlate = item.VCRegistrationNumber;
                asTwentyFourTransaction.VehicleId = int.Parse(item.VCNumber);
                //asTwentyFourTransaction.TransactionAmount =
                //asTwentyFourTransaction.CurrencyId =
                //asTwentyFourTransaction.CurrencyCode =
                //asTwentyFourTransaction.GrossAmount =
                //asTwentyFourTransaction.TransactionValue =
                //asTwentyFourTransaction.Unit =
                //asTwentyFourTransaction.TransactionCountryName =
                //asTwentyFourTransaction.TransactionCountryCode =
                //asTwentyFourTransaction.TransactionLocation =
                //asTwentyFourTransaction.ObuId =
                //2 olan 
                asTwentyFourTransaction.StatusId = 1;
                //asTwentyFourTransaction.StatusCode =

                _tld.L_ROD_AsTwentyFourTransaction.Add(asTwentyFourTransaction);
                _tld.SaveChanges();
            }

            return new Result() { IsSuccess = true };
        }
        catch (Exception ex)
        {
            return new Result() { IsSuccess = false, UserMessage = ex.Message };
        }
    }
}
C# .NET 日期时间 2

评论

0赞 Klaus Gütter 5/15/2023
的价值是什么?item.entryTransactionDate
0赞 Charlieface 5/15/2023
请显示 SQL 中的表定义,以及匹配的 C# 定义
0赞 Klaus Gütter 5/15/2023
大概是 stackoverflow.com/questions/1331779/......

答: 暂无答案