UpdateDataSet and exceptions - handling bad data

Topics: Data Access Application Block
Apr 9, 2009 at 8:24 PM
I am processing inserts/updates in a dataset with parent/child tables using updatedataset method.  If any record happens to cause a sql error, I get back an exception mostly (SqlException or a DBConcurrencyException)  

My question

1. Is there a way to identify the records that caused the exception to occur?

Apr 9, 2009 at 8:53 PM
When I set UpdateBehavior.Continue the exception is not thrown, but I have the same question - Is there a way to identify bad records that were skipped?
Apr 13, 2009 at 8:12 AM
Hi,

I have an idea, but I dont know if this is the best approach. So, what i did (I used the DataAccessQuickStart, in the SalesData.cs <SalesData.UpdateProducts()>) is, after the update has been performed, and I still have reference to the dataSet, i will iterate to the table in the dataset and check for DataRow.HasError. Like this:

            foreach (DataRow item in productsDataSet.Tables["Products"].Rows)

            {

                if(item.HasErrors)

                {

                    errorRows.Add(item);

                }

            }


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 13, 2009 at 4:38 PM
Ok, thanks! Found that this also works to get the rows with errors  (RowError) or you can get the specific column error as well.

   foreach (DataTable table in dataSet.Tables)
DataRow[] rowsInError = table.GetErrors();