2

当使用可为空的日期时间列插入我的表时,插入DateTime.MinDate会引发错误:

“将 char 数据类型转换为日期时间数据类型导致日期时间值超出范围。”

然而,当我这样做时,MaxDate它工作正常吗?我实际上想将此值插入为空,但在PropertyInfo.SetValue()传递空值时只是自动设置为MinDate,有什么建议吗?

4

1 回答 1

3

Sql ServerDateTime的范围是 1753-01-01 到 9999-12-31,而.NET 的DateTime范围是0001-01-01 12:00:00 午夜到 9999-12-31 11:59:59 PM

所以DateTime.MinValue低于 Sql Server 的最小值,同时DateTime.MaxValue适合 Sql Servers DateTime


使用 nullables:DateTime?能够在内存中有一个 null。

于 2011-03-08T11:04:09.600 回答