Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implicit conversion between '<null>' and 'System.DateTime' error

Tags:

c#

private DateTime? pApproveDate=null;
pApproveDate =(Reader["ApproveDate"]==DBNull.Value)?null: Convert.ToDateTime(Reader["ApproveDate"]);

Above code is generating the following error during compile time- Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'System.DateTime'

like image 837
s.k.paul Avatar asked Nov 27 '22 14:11

s.k.paul


1 Answers

Cast it to DateTime?:

private DateTime? 
pApproveDate=null;
pApproveDate =(Reader["ApproveDate"]==DBNull.Value)?(DateTime?)null:       
    Convert.ToDateTime(Reader["ApproveDate"]);
like image 136
It'sNotALie. Avatar answered Dec 16 '22 03:12

It'sNotALie.