Table is nullable DateTime, but DataSet throws an exception?

前端 未结 9 1220
悲哀的现实
悲哀的现实 2020-12-13 14:42

I\'m attempting to use the DataSet designer to create a datatable from a query. I got this down just fine. The query used returns a nullable datetime column from the datab

9条回答
  •  死守一世寂寞
    2020-12-13 15:08

    In DataSet Designer, use System.Object data type instead of System.DateTime and set NullValue to (Null) and DefaultValue to and when it is needed, convert it such as:

    var row1 = dateSet1.table1.FirstOrDefault();
    if (row1 == null)
        return;
    DateTime? date = (DateTime?) row1.ObjectDate;
    

提交回复
热议问题