none
Adding row with NULL values to a DataSet RRS feed

  • Question

  • I have a strongly typed DataSet that has some nullable columns. I know that I can use IsXXXNull() and SetXXXNull() for existing columns, but how do I create a new row containing NULL values?

    Let's say I have a table holding the names and ages of my friends. What if I don't Jill's age at the time of creation?

    MyDataSet ds = new MyDataSet();
    ds.MyTable.AddMyTableRow("Jack", 25);
    ds.MyTable.AddMyTableRow("Jill", /* what goes here?, this parameter is of type int, not Nullable<int> so neither null nor DBNull will work */ );

    Thanks,
    Steve
    Tuesday, April 22, 2008 6:26 PM

Answers

  • I don't think the strongly-typed DataTable supports this.  You either have to add the row and then set its nullable columns to nul with the SetXXXNull() method, or bypass the AddXXXRow method, by creating the row with the base NewRow() method and setting the row's columns manually.

    Tuesday, April 22, 2008 6:53 PM

All replies

  • I don't think the strongly-typed DataTable supports this.  You either have to add the row and then set its nullable columns to nul with the SetXXXNull() method, or bypass the AddXXXRow method, by creating the row with the base NewRow() method and setting the row's columns manually.

    Tuesday, April 22, 2008 6:53 PM
  • That's what I thought. Thanks.

    Here's to hoping they update the strongly typed datasets with Nullable<T> support soon.
    Tuesday, April 22, 2008 7:48 PM