System.Data Namespace DataTable Class
Returns the collection of parent relations for this DataTable.
Script |
[ DataRelationCollection variable = ] DataTable.ParentRelations |
The property is read only with no default value.
The following example uses the ParentRelations property to return each parent DataRelation in a DataTable. Each relation is then used as an argument in the GetParentRows method of the DataRow to return an array of rows. The value of each column in the row is then printed.
Private void ParentRelationsDemo ( DataTable myTable ) {
DataRow [ ] arrRows;
foreach ( DataRelation rel in myTable.ParentRelations ) {
foreach ( DataRow row in myTable.Rows ) {
arrRows = row.GetParentRows ( rel );
// print values of rows.
for ( int i = 0; i < arrRows.Length; i++ ) {
foreach ( DataColumn col in myTable.Columns ) {
Response.Write ( arrRows [ ] [ col ] );
}
}
}
}
}
Private Sub ParentRelationsDemo ( myTable As DataTable )
Dim arrRows ( ) As DataRow
Dim rel As DataRelation, row As DataRow
Dim col As DataColumn, i As Integer
For Each rel In myTable.ParentRelations
For Each row In myTable.Rows
arrRows = row.GetParentRows ( rel )
' print values of rows.
For i = 0 To arrRows.Length - 1
For Each col In myTable.Columns
Response.Write ( arrRows ( i ) ( col ) )
Next col
Next i
Next row
Next rel
End Sub |
|
C# |
VB |
DataTable Members ChildRelations DataRelation DataSet Relations