System.Data Namespace DataRow Class
Returns the child rows of a DataRow.
1. Returns the child rows of a DataRow using a specified DataRelation object.
2. Returns the child rows of a DataRow using a specified DataRelation name.
3. Returns a version of the child rows of a DataRow using a specified DataRelation object.
4. Returns a version of the child rows of a DataRow using a specified DataRelation name.
The following example uses the GetChildRows to return the child DataRow objects from the Products table, for every parent DataRow from the Categories table.
NOTE: This example uses one of the overloaded versions of GetChildRows. For other examples that may be available, see the individual overload topics.
// 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 ( "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 ( "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 ChildRelations DataRelation GetParentRows Relations