Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exception "nullable value must have a value" for datetime [duplicate]

Tags:

c#

asp.net

vb.net

I am trying to assign 'null' value to Datetime? object. But it is throwing "nullable value must have a value" exception.

 //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)))

How to solve this

like image 765
James123 Avatar asked Feb 17 '26 23:02

James123


1 Answers

fact_Initiative.Start_Date =If(String.IsNullOrEmpty(item.PlannedStartDate), CType(Nothing, DateTime?), DateTime.Parse(item.PlannedStartDate))
like image 157
Damith Avatar answered Feb 19 '26 13:02

Damith