9.7 Navigating Parent and Child Rows

A DataRow can have both parent and child rows if the DataTable that it belongs to has a DataRelation set up with another table. There are three methods that allow these relationships to be navigated. The GetParentRow( ) method returns the parent row as a DataRow object. The GetParentRows( ) method returns the parent rows as an array of DataRow objects. Both methods require either the name of the DataRelation or a reference to the DataRelation as an argument. An optional argument specifying the DataRowVersion allows control over the version of the rows returned.

The SetParentRow( ) method changes the parent row for the DataRow. This method simply takes a reference to the new parent DataRow and an optional DataRelation argument, if required.

Finally, the GetChildRows( ) method returns the child rows as an array of DataRow objects. The name of the DataRelation or a reference to the DataRelation is required as an argument. An optional argument specifying the DataRowVersion allows control over the version of rows returned.

Navigating parent and child rows is explored in detail in Chapter 11.



    Part I: ADO.NET Tutorial
    Part II: ADO.NET Core Classes
    Part III: API Quick Reference