asp.net.ph

DataTable.ChildRelations Property

System.Data Namespace   DataTable Class


Returns the collection of child relations for this DataTable.

Syntax


Script [ DataRelationCollection variable = ] DataTable.ChildRelations

Property Value


variable Returns the DataRelationCollection that contains the child relations for the table; otherwise a null value if no DataRelation objects exist.

The property is read only with no default value.

Remarks

A DataRelation defines the relationship between two tables. Typically, two tables are linked through a single field that contains the same data. For example, a table which contains address data may have a single field containing codes that represent countries/regions. A second table that contains country/region data will have a single field that contains the code that identifies the country/region, and it is this code which is inserted into the corresponding field in the first table.

A DataRelation, then, contains at least four pieces of information:

  1. the name of the first table,
  2. the column name in the first table,
  3. the name of the second table, and
  4. the column name in the second table.

Example

The following example uses the ChildRelations property to return each child DataRelation in a DataTable. Each relation is then used as an argument in the GetChildRows method of the DataRow to return an array of rows. The value of each column in the row is then printed.

Private void ChildRelationsDemo ( DataTable myTable ) {
   /* For each row in the table, get the child rows using the ChildRelations. 
   For each item in the array, print the value of each column. */
   DataRow [ ] arrRows;

   foreach ( DataRelation myRelation in myTable.ChildRelations ) {
      foreach ( DataRow myRow in myTable.Rows ) {
         arrRows = myRow.GetChildRows ( myRelation );
         // print values of rows.
        for ( int i = 0; i < arrRows.Length; i++ ) {
            foreach ( DataColumn myColumn in myTable.Columns ) {
               Response.Write ( arrRows [ ] [ myColumn.ColumnName ] );
           }
        }
     }
   }
}
  C# VB

See Also

DataTable Members   ParentRelations   DataRelation   GetParentRows   GetChildRows Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph