none
Deleting rows which fail to meet constraints RRS feed

  • Question

  • Hi,

    I wish to fill a dataset table and to delete any rows that do not meet constraints. Here is an example of my code for doing this -


    try
    {
    this.testConfTableAdapter.Fill(this.rDS.testConf);
    }
    catch (ConstraintException constraintException)
    {
    if (this.rDS.testConf.HasErrors)
    {
    foreach (rDDS.testConfRow testConfRow in this.rDS.testConf.GetErrors())
    {
    testConfRow.Delete();
    }

    }
    }

    If the Fill function finds an error row, will it continue to read in all the remaining rows anyway? If so, does the above code do what I wish it to do? Any other suggestions?

    Thanks,

    Barry.
    Thursday, August 28, 2008 1:03 PM

All replies

  • Hi Barry,

     

    Yes Fill() will process all the rows and then throw the exception, the rows that have constraint errors will be marked with Error and you'll be able to get them with GetErrors().

     

    Remember that testConfRow.Delete() will mark the rows as deleted, if you need to remove them call AcceptChanges().

     

    Let me know if this helps. Best Regards

    Juan

    Thursday, September 11, 2008 1:50 AM
    Moderator