【发布时间】:2013-12-04 04:36:18
【问题描述】:
我正在尝试将“null”值分配给 Datetime? 对象。但它抛出"nullable value must have a value" 异常。
//item.PlannedStartDate value is nothing.
fact_Initiative.Start_Date = If([String].IsNullOrEmpty(item.PlannedStartDate),
DBNull.Value, CType(Convert.ToDateTime(item.PlannedStartDate),
System.Nullable(Of Date)))
如何解决这个问题
【问题讨论】:
-
您确定 fact_Initiative.Start_Date 的类型为 Nullable
? -
另外,我怀疑
DBNull.Value会在这里工作。你能展示一些上下文代码吗?我觉得如果我们还有更多工作要做的话,会有一个很好的解决方案在等待。 -
@AlexeyRaga 它是
DateTime?