Adding rows with NULL columns to a strongly typed 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 */ );

    Tuesday, April 22, 2008 4:37 PM


  • You can't use the that Add___Row "shortcut" syntax in this case.


    Code Snippet

    MyDataSet ds = new MyDataSet();

    MyDataSet.MyTableRow dr = ds.MyTable.NewMyTableRow();

    // Set the columns one by one. You can leave out columns you want defaulted.

    dr.Name = "Jill";



    Wednesday, April 23, 2008 12:27 AM