本文整理汇总了VB.NET中System.Data.DataTable.WriteXml方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DataTable.WriteXml方法的具体用法?VB.NET DataTable.WriteXml怎么用?VB.NET DataTable.WriteXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataTable 的用法示例。
在下文中一共展示了DataTable.WriteXml方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Main
Sub Main()
Dim ds As New DataSet
Dim customerTable As DataTable = GetCustomers()
Dim orderTable As DataTable = GetOrders()
ds.Tables.Add(customerTable)
ds.Tables.Add(orderTable)
ds.Relations.Add("CustomerOrder", _
New DataColumn() {customerTable.Columns(0)}, _
New DataColumn() {orderTable.Columns(1)}, True)
Dim writer As New System.IO.StringWriter
customerTable.WriteXml(writer, XmlWriteMode.WriteSchema, False)
PrintOutput(writer, "Customer table, without hierarchy")
writer = New System.IO.StringWriter
customerTable.WriteXml(writer, XmlWriteMode.WriteSchema, True)
PrintOutput(writer, "Customer table, with hierarchy")
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Function GetOrders() As DataTable
' Create sample Customers table, in order
' to demonstrate the behavior of the DataTableReader.
Dim table As New DataTable
' Create three columns, OrderID, CustomerID, and OrderDate.
table.Columns.Add(New DataColumn("OrderID", GetType(System.Int32)))
table.Columns.Add(New DataColumn("CustomerID", GetType(System.Int32)))
table.Columns.Add(New DataColumn("OrderDate", GetType(System.DateTime)))
' Set the OrderID column as the primary key column.
table.PrimaryKey = New DataColumn() {table.Columns(0)}
table.Rows.Add(New Object() {1, 1, #12/2/2003#})
table.Rows.Add(New Object() {2, 1, #1/3/2004#})
table.Rows.Add(New Object() {3, 2, #11/13/2004#})
table.Rows.Add(New Object() {4, 3, #5/16/2004#})
table.Rows.Add(New Object() {5, 3, #5/22/2004#})
table.Rows.Add(New Object() {6, 4, #6/15/2004#})
table.AcceptChanges()
Return table
End Function
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(System.Int32))
table.Columns.Add("Name", GetType(System.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 Sub PrintOutput( _
ByVal writer As System.IO.TextWriter, ByVal caption As String)
Console.WriteLine("==============================")
Console.WriteLine(caption)
Console.WriteLine("==============================")
Console.WriteLine(writer.ToString())
End Sub
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:75,代码来源:DataTable.WriteXml
示例2: Main
Sub Main()
Dim ds As New DataSet
Dim customerTable As DataTable = GetCustomers()
Dim orderTable As DataTable = GetOrders()
ds.Tables.Add(customerTable)
ds.Tables.Add(orderTable)
ds.Relations.Add("CustomerOrder", _
New DataColumn() {customerTable.Columns(0)}, _
New DataColumn() {orderTable.Columns(1)}, True)
Dim writer As New System.IO.StringWriter
customerTable.WriteXml(writer, True)
PrintOutput(writer, "Customer table, with hierarchy")
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Function GetOrders() As DataTable
' Create sample Customers table, in order
' to demonstrate the behavior of the DataTableReader.
Dim table As New DataTable
' Create three columns, OrderID, CustomerID, and OrderDate.
table.Columns.Add(New DataColumn("OrderID", GetType(System.Int32)))
table.Columns.Add(New DataColumn("CustomerID", GetType(System.Int32)))
table.Columns.Add(New DataColumn("OrderDate", GetType(System.DateTime)))
' Set the OrderID column as the primary key column.
table.PrimaryKey = New DataColumn() {table.Columns(0)}
table.Rows.Add(New Object() {1, 1, #12/2/2003#})
table.Rows.Add(New Object() {2, 1, #1/3/2004#})
table.Rows.Add(New Object() {3, 2, #11/13/2004#})
table.Rows.Add(New Object() {4, 3, #5/16/2004#})
table.Rows.Add(New Object() {5, 3, #5/22/2004#})
table.Rows.Add(New Object() {6, 4, #6/15/2004#})
table.AcceptChanges()
Return table
End Function
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(System.Int32))
table.Columns.Add("Name", GetType(System.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 Sub PrintOutput( _
ByVal stream As System.IO.TextWriter, ByVal caption As String)
Console.WriteLine("==============================")
Console.WriteLine(caption)
Console.WriteLine("==============================")
Console.WriteLine(stream.ToString())
End Sub
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:71,代码来源:DataTable.WriteXml
注:本文中的System.Data.DataTable.WriteXml方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论