當我做下面我得到:不能隱式轉換類型System.DateTime?爲System.DateTime
inv.RSV = pid.RSVDate
我得到以下幾點:不能隱式轉換類型System.DateTime的?到System.DateTime。
在這種情況下,inv.RSV是DateTime,pid.RSVDate是DateTime?
我嘗試以下,但沒有成功:
if (pid.RSVDate != null)
{
inv.RSV = pid.RSVDate != null ? pid.RSVDate : (DateTime?)null;
}
如果pid.RSVDate是空的,我喜歡不分配inv.RSV任何在這種情況下,這將是空。
inv.RSV爲null開頭。我怎麼說不更新它沒有價值的pid.RSVDate –
@NatePet你檢查'pid.RSVDate.HasValue'。如果它沒有賦值,那麼'HasValue'將返回'false',在這種情況下,你不會更新你的其他值。根據你的錯誤信息,'inv.RSV'是一個'DateTime',它不可能有一個空值。如果你想給它賦值null,改變它的類型爲'DateTime?'爲空。 –
@NatePet,「inv.RSV爲null開始」:你確定嗎? DateTime **不能爲空** –