c# - 日期时间异常 "nullable value must have a value"

标签 c# asp.net vb.net

<分区>

我正在尝试将“空”值分配给 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 =If(String.IsNullOrEmpty(item.PlannedStartDate), CType(Nothing, DateTime?), DateTime.Parse(item.PlannedStartDate))

关于c# - 日期时间异常 "nullable value must have a value",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20366940/

相关文章:

c# - 401 未经授权的异常与 SSL 的 WebRequest

c# - 从C#运行C代码

vb.net - 如何检查VB.NET代码中Access SysCmd失败的原因?

c# - 将 powershell 脚本的输出绑定(bind)到 asp.net c# 中的 gridview

c# - 以两个字节为单位查找公共(public)前缀的长度

c# - 如何将脚本从 .ascx 添加到 .aspx <HEAD> 部分

asp.net - web.config 中的加密和未加密连接字符串?

c# - 在没有当前 HttpContext 可用的情况下访问 HttpApplicationState

java - 收到推送通知,但没有消息

arrays - VBA中的列表和数组