RowNotInTableException

M

Mike Kiefer

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
}
 
M

Mike Kiefer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top