本文整理匯總了VB.NET中System.Data.DataTableReader.DataTableReader構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET DataTableReader構造函數的具體用法?VB.NET DataTableReader怎麽用?VB.NET DataTableReader使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DataTableReader構造函數的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: TestConstructor
Private Sub TestConstructor()
' Create two data adapters, one for each of the two
' DataTables to be filled.
Dim customerDataTable As DataTable = GetCustomers()
Dim productDataTable As DataTable = GetProducts()
' Create the new DataTableReader.
Using reader As New DataTableReader( _
New DataTable() {customerDataTable, productDataTable})
' Print the contents of each of the result sets.
Do
PrintColumns(reader)
Loop While reader.NextResult()
End Using
Console.WriteLine("Press Enter to finish.")
Console.ReadLine()
End Sub
Private Function GetCustomers() As DataTable
' Create sample Customers table, in order
' to demonstrate the behavior of the DataTableReader.
Dim table As New DataTable
' Create two columns, ID and Name.
Dim idColumn As DataColumn = table.Columns.Add("ID", _
GetType(Integer))
table.Columns.Add("Name", GetType(String))
' Set the ID column as the primary key column.
table.PrimaryKey = New DataColumn() {idColumn}
table.Rows.Add(New Object() {1, "Mary"})
table.Rows.Add(New Object() {2, "Andy"})
table.Rows.Add(New Object() {3, "Peter"})
table.Rows.Add(New Object() {4, "Russ"})
Return table
End Function
Private Function GetProducts() As DataTable
' Create sample Products table, in order
' to demonstrate the behavior of the DataTableReader.
Dim table As New DataTable
' Create two columns, ID and Name.
Dim idColumn As DataColumn = table.Columns.Add("ID", _
GetType(Integer))
table.Columns.Add("Name", GetType(String))
' Set the ID column as the primary key column.
table.PrimaryKey = New DataColumn() {idColumn}
table.Rows.Add(New Object() {1, "Wireless Network Card"})
table.Rows.Add(New Object() {2, "Hard Drive"})
table.Rows.Add(New Object() {3, "Monitor"})
table.Rows.Add(New Object() {4, "CPU"})
Return table
End Function
Private Sub PrintColumns( _
ByVal reader As DataTableReader)
' Loop through all the rows in the DataTableReader.
Do While reader.Read()
For i As Integer = 0 To reader.FieldCount - 1
Console.Write(reader(i).ToString() & " ")
Next
Console.WriteLine()
Loop
End Sub