Table is nullable DateTime, but DataSet throws an exception?

前端 未结 9 1209
悲哀的现实
悲哀的现实 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:29

    I did this to insert value NULL in a DateTime column,

    assuming that I have a nullable DateTime column in Database, I retrieved some data from the database in an object called response and I want to insert nullable DateTime value in the DataSet column that called RenewDate:

    // create anew row of the same type of your table row
    var rw = ds.StudentActionPrintDT.NewStudentActionPrintDTRow();
    
    // check for null value
    if(!response.RenewDate.HasValue)
    {
      // if null, then the let DataSet to set it null by it's own way 
      rw.SetRenewDateNull();
    }
    else
    {
      // if not null set value to the datetime value
      rw.RenewDate = response.RenewDate.Value;
    }
    // add the created row to the dateset [DataSetName].[ColumnName].Add[ColumnName]Row([The Created Row]);
    ds.StudentActionPrintDT.AddStudentActionPrintDTRow(rw);
    

提交回复
热议问题