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 [ ];
- relation
- The DataRelation to use.
An array of DataRow objects ( or an array of length zero ).
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.
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>";
}
' iterate over parent rows ( Categories )
Dim category As DataRow
For Each 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 )
Dim product As DataRow
For Each 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>"
Next product
html += "</table>"
Next category |
|
C# |
VB |
Show me
DataRow Members DataRow.GetChildRows Overload List