Of course, as soon as I posted about the problem I figured it out...
The problem was that AcceptChanges was triggering the
Stores_StoresRowChanged event and that event handler
wasn't checking to see if (e.Row.RowState == DataRowState.Detached) before
doing it's work. Adding the proper checks solved my problem.
"Mike Kiefer" <mdk-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I have a typed data set with Stores and CartItems, where there is a
>relationship from the Stores table to the CartItems table. Whenever a row
>in the CartItems table is deleted, the following code fires as part of the
> CartItems_CartItemsRowDeleted event for the dataset, deleting the parent
> row if it is the last item from that store in the cart. For some reason,
> when _cartDS.AcceptChanges() is called after the parent row is deleted, a
> RowNotInTableException is thrown. I don't understand why this would occur
> and can't figure out how to fix it or work around it. Any help would be
> greatly appreciated.
>
> Guid storeGUID = (Guid)e.Row[_cartDS.CartItems.StoreGUIDColumn,
> DataRowVersion.Original];
> ShoppingCartDS.StoresRow row = _cartDS.Stores.FindByStoreGUID(storeGUID);
> if (row != null)
> {
>
> ShoppingCartDS.CartItemsRow[] childRows = row.GetCartItemsRows();
> if ((childRows == null) || (childRows.Length == 0))
> row.Delete(); // If this code isn't executed then AcceptChanges
> works fine with no exceptions thrown
> }
>
|