Link to home
Create AccountLog in
Avatar of davidburson

asked on

how to get deleted child rows from a parent row and DataRelation in .NET

I have a strongly-typed dataset (VB.NET), using .NET Framework 2.0. Given a DataRow in a parent DataTable and a DataRelation, I need to find all related rows in the child DataTable that have a RowState = DataRowState.Deleted.

Unfortunately for me, DataRow.GetChildRows(DataRelation) does not include child rows that have a RowState of DataRowState.Deleted.

Currently I'm doing a table scan of the child table to find the deleted rows that match the criteria of the relation, but my tables have become too large for that to work. How can I get the deleted child rows with decent performance?
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of davidburson


This appears to be working.  Looks like the only way to get the deleted rows is to use DataRowVersion.Original, which gives me added and unchanged rows too, so I just have to iterate through and grab the deleted ones.

Much better than a table scan!
had to experiment with which datarowversion to use, which turned out to be counter-intuitive.  Also, this solution doesn't give exactly what I want, so I have to do a little extra to get what I want.