本文整理汇总了VB.NET中System.Data.DataSet.Load方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DataSet.Load方法的具体用法?VB.NET DataSet.Load怎么用?VB.NET DataSet.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataSet 的用法示例。
在下文中一共展示了DataSet.Load方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Main
Sub Main()
Dim dataSet As New DataSet
Dim customerTable As New DataTable
Dim productTable As New DataTable
' This information is cosmetic, only.
customerTable.TableName = "Customers"
productTable.TableName = "Products"
' Add the tables to the DataSet:
dataSet.Tables.Add(customerTable)
dataSet.Tables.Add(productTable)
' Load the data into the existing DataSet.
Dim reader As DataTableReader = GetReader()
dataSet.Load(reader, LoadOption.OverwriteChanges, _
customerTable, productTable)
' Print out the contents of each table:
For Each table As DataTable In dataSet.Tables
PrintColumns(table)
Next
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Function GetCustomers() As DataTable
' Create sample Customers table.
Dim table As New DataTable
table.TableName = "Customers"
' 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() {0, "Mary"})
table.Rows.Add(New Object() {1, "Andy"})
table.Rows.Add(New Object() {2, "Peter"})
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
table.TableName = "Products"
' 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() {0, "Wireless Network Card"})
table.Rows.Add(New Object() {1, "Hard Drive"})
table.Rows.Add(New Object() {2, "Monitor"})
table.Rows.Add(New Object() {3, "CPU"})
Return table
End Function
Private Function GetReader() As DataTableReader
' Return a DataTableReader containing multiple
' result sets, just for the sake of this demo.
Dim dataSet As New DataSet
dataSet.Tables.Add(GetCustomers())
dataSet.Tables.Add(GetProducts())
Return dataSet.CreateDataReader()
End Function
Private Sub PrintColumns( _
ByVal table As DataTable)
Console.WriteLine()
Console.WriteLine(table.TableName)
Console.WriteLine("=========================")
' Loop through all the rows in the table.
For Each row As DataRow In table.Rows
For Each col As DataColumn In table.Columns
Console.Write(row(col).ToString() & " ")
Next
Console.WriteLine()
Next
End Sub
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:92,代码来源:DataSet.Load
示例2: Main
Sub Main()
Dim dataSet As New DataSet
Dim table As DataTable
Dim reader As DataTableReader = GetReader()
' The tables listed as parameters for the Load method
' should be in the same order as the tables within the IDataReader.
dataSet.Load(reader, LoadOption.Upsert, "Customers", "Products")
For Each table In dataSet.Tables
PrintColumns(table)
Next
' Now try the example with the DataSet
' already filled with data:
dataSet = New DataSet
dataSet.Tables.Add(GetCustomers())
dataSet.Tables.Add(GetProducts())
' Retrieve a data reader containing changed data:
reader = GetReader()
' Load the data into the existing DataSet. Retrieve the order of the
' the data in the reader from the
' list of table names in the parameters. If you specify
' a new table name here, the Load method will create
' a corresponding new table.
dataSet.Load(reader, LoadOption.Upsert, "NewCustomers", "Products")
For Each table In dataSet.Tables
PrintColumns(table)
Next
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Function GetCustomers() As DataTable
' Create sample Customers table.
Dim table As New DataTable
table.TableName = "Customers"
' 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() {0, "Mary"})
table.Rows.Add(New Object() {1, "Andy"})
table.Rows.Add(New Object() {2, "Peter"})
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
table.TableName = "Products"
' 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() {0, "Wireless Network Card"})
table.Rows.Add(New Object() {1, "Hard Drive"})
table.Rows.Add(New Object() {2, "Monitor"})
table.Rows.Add(New Object() {3, "CPU"})
Return table
End Function
Private Function GetReader() As DataTableReader
' Return a DataTableReader containing multiple
' result sets, just for the sake of this demo.
Dim dataSet As New DataSet
dataSet.Tables.Add(GetCustomers())
dataSet.Tables.Add(GetProducts())
Return dataSet.CreateDataReader()
End Function
Private Sub PrintColumns( _
ByVal table As DataTable)
Console.WriteLine()
Console.WriteLine(table.TableName)
Console.WriteLine("=========================")
' Loop through all the rows in the table.
For Each row As DataRow In table.Rows
For Each col As DataColumn In table.Columns
Console.Write(row(col).ToString() & " ")
Next
Console.WriteLine()
Next
End Sub
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:98,代码来源:DataSet.Load
示例3: Main
Sub Main()
Dim dataSet As New DataSet
Dim table As New DataTable()
' Attempt to load data from a data reader in which
' the schema is incompatible with the current schema.
' If you use exception handling, you won't get the chance
' to examine each row, and each individual table,
' as the Load method progresses.
' By taking advantage of the FillErrorEventHandler delegate,
' you can interact with the Load process as an error occurs,
' attempting to fix the problem, or simply continuing or quitting
' the Load process.:
dataSet = New DataSet()
table = GetIntegerTable()
dataSet.Tables.Add(table)
Dim reader As New DataTableReader(GetStringTable())
dataSet.Load(reader, LoadOption.OverwriteChanges, _
AddressOf FillErrorHandler, table)
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Sub FillErrorHandler(ByVal sender As Object, _
ByVal e As FillErrorEventArgs)
' You can use the e.Errors value to determine exactly what
' went wrong.
If e.Errors.GetType Is GetType(System.FormatException) Then
Console.WriteLine("Error when attempting to update the value: {0}", _
e.Values(0))
End If
' Setting e.Continue to True tells the Load
' method to continue trying. Setting it to False
' indicates that an error has occurred, and the
' Load method raises the exception that got
' you here.
e.Continue = True
End Sub
Private Function GetIntegerTable() As DataTable
' Create sample table with a single Int32 column.
Dim table As New DataTable
Dim idColumn As DataColumn = table.Columns.Add("ID", _
GetType(Integer))
' Set the ID column as the primary key column.
table.PrimaryKey = New DataColumn() {idColumn}
table.Rows.Add(New Object() {4})
table.Rows.Add(New Object() {5})
table.TableName = "IntegerTable"
table.AcceptChanges()
Return table
End Function
Private Function GetStringTable() As DataTable
' Create sample table with a single String column.
Dim table As New DataTable
Dim idColumn As DataColumn = table.Columns.Add("ID", _
GetType(String))
' Set the ID column as the primary key column.
table.PrimaryKey = New DataColumn() {idColumn}
table.Rows.Add(New Object() {"Mary"})
table.Rows.Add(New Object() {"Andy"})
table.Rows.Add(New Object() {"Peter"})
table.AcceptChanges()
Return table
End Function
Private Sub PrintColumns( _
ByVal table As DataTable)
' Loop through all the rows in the DataTableReader.
For Each row As DataRow In table.Rows
For Each col As DataColumn In table.Columns
Console.Write(row(col).ToString() & " ")
Next
Console.WriteLine()
Next
End Sub
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:86,代码来源:DataSet.Load
注:本文中的System.Data.DataSet.Load方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论