当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET DataSet.CreateDataReader方法代码示例

本文整理汇总了VB.NET中System.Data.DataSet.CreateDataReader方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DataSet.CreateDataReader方法的具体用法?VB.NET DataSet.CreateDataReader怎么用?VB.NET DataSet.CreateDataReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.DataSet的用法示例。


在下文中一共展示了DataSet.CreateDataReader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Main

Private emptyTable As DataTable
Private customerTable As DataTable
Private productTable As DataTable

Sub Main()
  Dim dataSet As New DataSet
  ' Add some DataTables to the DataSet, including
  ' an empty DataTable:

  emptyTable = New DataTable()
  productTable = GetProducts()
  customerTable = GetCustomers()

  dataSet.Tables.Add(customerTable)
  dataSet.Tables.Add(emptyTable)
  dataSet.Tables.Add(productTable)
  TestCreateDataReader(dataSet)

  Console.WriteLine("Press any key to continue.")
  Console.ReadKey()
End Sub

Private Sub TestCreateDataReader(ByVal dataSet As DataSet)
  ' Given a DataSet, retrieve a DataTableReader
  ' allowing access to all the DataSet's data.
  ' Even though the dataset contains three DataTables,
  ' this code will only display the contents of two of them,
  ' because the code has limited the results to the 
  ' DataTables stored in the tables array. Because this
  ' parameter is declared using the ParamArray keyword, 
  ' you could also include a list of DataTable instances 
  ' individually, as opposed to supplying an array of 
  ' DataTables, as in this example:
  Using reader As DataTableReader = _
      dataSet.CreateDataReader(productTable, emptyTable)
    Do
      If Not reader.HasRows Then
        Console.WriteLine("Empty DataTableReader")
      Else
        PrintColumns(reader)
      End If
      Console.WriteLine("========================")
    Loop While reader.NextResult()
  End Using
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"})
  table.AcceptChanges()
  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"})
  table.AcceptChanges()
  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
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:97,代码来源:DataSet.CreateDataReader

示例2: Main

Private emptyTable As DataTable
Private customerTable As DataTable
Private productTable As DataTable

Sub Main()
  Dim dataSet As New DataSet
  ' Add some DataTables to the DataSet, including
  ' an empty DataTable:

  emptyTable = New DataTable()
  productTable = GetProducts()
  customerTable = GetCustomers()

  dataSet.Tables.Add(customerTable)
  dataSet.Tables.Add(emptyTable)
  dataSet.Tables.Add(productTable)
  TestCreateDataReader(dataSet)

  Console.WriteLine("Press any key to continue.")
  Console.ReadKey()
End Sub

Private Sub TestCreateDataReader(ByVal dataSet As DataSet)
  ' Given a DataSet, retrieve a DataTableReader
  ' allowing access to all the DataSet's data.
  ' Even though the dataset contains three DataTables,
  ' this code will only display the contents of two of them,
  ' because the code has limited the results to the 
  ' DataTables stored in the tables array. Because this
  ' parameter is declared using the ParamArray keyword, 
  ' you could also include a list of DataTable instances 
  ' individually, as opposed to supplying an array of 
  ' DataTables, as in this example:
  Using reader As DataTableReader = _
    dataSet.CreateDataReader(productTable, emptyTable)
    Do
      If Not reader.HasRows Then
        Console.WriteLine("Empty DataTableReader")
      Else
        PrintColumns(reader)
      End If
      Console.WriteLine("========================")
    Loop While reader.NextResult()
  End Using
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
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:95,代码来源:DataSet.CreateDataReader

示例3: Main

Sub Main()
  Dim dataSet As New DataSet
  ' Add some DataTables to the DataSet, including
  ' an empty DataTable:
  dataSet.Tables.Add(GetCustomers())
  dataSet.Tables.Add(New DataTable())
  dataSet.Tables.Add(GetProducts())
  TestCreateDataReader(dataSet)

  Console.WriteLine("Press any key to continue.")
  Console.ReadKey()
End Sub

Private Sub TestCreateDataReader(ByVal dataSet As DataSet)
  ' Given a DataSet, retrieve a DataTableReader
  ' allowing access to all the DataSet's data:
  Using reader As DataTableReader = dataSet.CreateDataReader()
    Do
      If Not reader.HasRows Then
        Console.WriteLine("Empty DataTableReader")
      Else
        PrintColumns(reader)
      End If
      Console.WriteLine("========================")
    Loop While reader.NextResult()
  End Using
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
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:77,代码来源:DataSet.CreateDataReader


注:本文中的System.Data.DataSet.CreateDataReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。