0
我定義這個在我的課休假日期時間選擇器返回1/1/0001 12:00:00 AM在C#
public DateTime? LineCheckSubmitDateTime { set; get; }
我需要用我的gridview
但有時我需要離開這個值爲空,但是當我離開它它返回1/1/0001 12:00:00 AM
所以這裏是我的代碼:
newObj.LineCheckSubmitDateTime = (Convert.ToDateTime(gridViewDetails.GetRowCellValue(rowHandle, "LineCheckSubmitDateTime"))==DateTime.Parse("1/1/0001 12:00:00 AM")) ? Convert.ToDateTime(gridViewDetails.GetRowCellValue(rowHandle, "LineCheckSubmitDateTime")):null;
所以兩個問題:
1:此代碼返回此錯誤:
Severity Code Description Project File Line
Error CS0173 Type of conditional expression cannot be determined because there is no implicit conversion between 'DateTime' and '<null>'
2:你有更好的解決辦法?
再次出現同樣的錯誤 –
@EhsanAkbar,在代碼中犯了一個錯誤,而不是'DateTime?'我有'DateTime'。代碼現在被修改。應該沒問題。 – Habib
哈比不幸,我有同樣的錯誤,你改變代碼? –