本文整理匯總了VB.NET中System.Data.DataTable.WriteXmlSchema方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET DataTable.WriteXmlSchema方法的具體用法?VB.NET DataTable.WriteXmlSchema怎麽用?VB.NET DataTable.WriteXmlSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.WriteXmlSchema方法的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.WriteXmlSchema(writer, False)
PrintOutput(writer, "Customer table, without hierarchy")
writer = New System.IO.StringWriter
customerTable.WriteXmlSchema(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 writer As System.IO.TextWriter, ByVal caption As String)
Console.WriteLine("==============================")
Console.WriteLine(caption)
Console.WriteLine("==============================")
Console.WriteLine(writer.ToString())
End Sub
示例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.WriteXmlSchema(writer, False)
PrintOutput(writer, "Customer table, without hierarchy")
writer = New System.IO.StringWriter
customerTable.WriteXmlSchema(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 writer As System.IO.TextWriter, ByVal caption As String)
Console.WriteLine("==============================")
Console.WriteLine(caption)
Console.WriteLine("==============================")
Console.WriteLine(writer.ToString())
End Sub