asp.net.ph

DataRow.GetChildRows Method ( DataRelation )

System.Data Namespace   DataRow Class


Returns the child rows of a DataRow using a specified DataRelation object.

[ VB ]
Overloads Public Function GetChildRows ( _
   ByVal relation As DataRelation _
) As DataRow ( )

[ C# ]
public DataRow [ ] GetChildRows (
   DataRelation relation
);

[ C++ ]
public: DataRow* GetChildRows (
   DataRelation* relation
 ) [ ];

[ JScript ]
public function GetChildRows (
   relation : DataRelation
) : DataRow [ ];

Parameters

relation
The DataRelation to use.

Return Value

An array of DataRow objects ( or an array of length zero ).

Exceptions


Exception Type Condition
RowNotInTableException Occurs when the row does not belong to the table.
ArgumentNullException Occurs when the relation is a null reference.
ArgumentException Occurs when the relation and row do not belong to the same table.
VersionNotFoundException Occurs when the row does not have this version of data.

Remarks

In a DataSet, the collection of all DataRelation objects for the data set is returned by the Relations method. The DataTable also contains a collection of DataRelation objects, returned by the ChildRelations property.

Example

The following example uses the GetChildRows to return the child DataRow objects from the Products table, for every parent DataRow from the Categories table.

// iterate over parent rows ( Categories )

foreach ( DataRow category in ds.Tables [ 0 ].Rows; ) {
   html += "<br><div class='header' style='color:maroon'><h5>" + 
      category [ "CategoryName" ] + "</h5></div>";

   // begin table headers markup
   html += "<table class='child' width=75% align='center' cellspacing=1>";
   html += "<tr><th>Product Name</th>";
   ...
   // iterate over child rows ( Products )

   foreach ( DataRow product in category.GetChildRows (
         ds.Relations [ "categoryId" ] ) ) {
      html += "<tr><td>" + product [ "ProductName" ] + "</td>";
      html += "<td>" + product [ "QuantityPerUnit" ] + "</td>";
      html += "<td align='right'>" + String.Format ( "{0:f2}", product [ "UnitPrice" ] ) + "</td>";
      html += "<td align='right'>" + product [ "UnitsInStock" ] + "</td></tr>";
   }
   html += "</table>";
}
  C# VB

 Show me 

See Also

DataRow Members   DataRow.GetChildRows Overload List 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