本文整理匯總了VB.NET中System.Data.DataTable.ChildRelations屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET DataTable.ChildRelations屬性的具體用法?VB.NET DataTable.ChildRelations怎麽用?VB.NET DataTable.ChildRelations使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.ChildRelations屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: GetChildRowsFromDataRelation
Public Sub GetChildRowsFromDataRelation()
' 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.
Dim table As DataTable = CreateDataSet().Tables("Customers")
Dim childRows() As DataRow
Dim relation as DataRelation
Dim row as DataRow
For Each relation In table.ChildRelations
For Each row In table.Rows
PrintRowValues(new DataRow() {row}, "Parent Row")
childRows = row.GetChildRows(relation)
' Print values of rows.
PrintRowValues(childRows, "child rows")
Next row
Next relation
End Sub
Public Function CreateDataSet() As DataSet
' create a DataSet with one table, two columns
Dim dataSet As DataSet
dataSet = new DataSet()
' create Customer table
Dim table As DataTable
table = new DataTable("Customers")
dataSet.Tables.Add(table)
table.Columns.Add("customerId", _
GetType(Integer)).AutoIncrement = true
table.Columns.Add("name", GetType(String))
table.PrimaryKey = new DataColumn() _
{ table.Columns("customerId") }
' create Orders table
table = new DataTable("Orders")
dataSet.Tables.Add(table)
table.Columns.Add("orderId", GetType(Integer)).AutoIncrement = true
table.Columns.Add("customerId", GetType(Integer))
table.Columns.Add("amount", GetType(Double))
table.PrimaryKey = new DataColumn() { table.Columns("orderId") }
' create relation
dataSet.Relations.Add(dataSet.Tables("Customers").Columns("customerId"), _
dataSet.Tables("Orders").Columns("customerId"))
' populate the tables
Dim orderId As Integer = 1
Dim customerId As Integer
Dim i As Integer
For customerId = 1 To 10
' add customer record
dataSet.Tables("Customers").Rows.Add( _
new object() { customerId, _
string.Format("customer{0}", customerId) })
' add 5 order records for each customer
For i = 1 To 5
dataSet.Tables("Orders").Rows.Add( _
new object() { orderId, customerId, orderId * 10 })
orderId = orderId+1
Next
Next
CreateDataSet = dataSet
End Function
private sub PrintRowValues(rows() As DataRow, label As String)
Console.WriteLine("\n{0}", label)
If rows.Length <= 0
Console.WriteLine("no rows found")
Exit Sub
End If
Dim row As DataRow
Dim column As DataColumn
For Each row In rows
For Each column In row.Table.Columns
Console.Write("\table {0}", row(column))
Next column
Console.WriteLine()
Next row
End Sub