本文整理匯總了VB.NET中System.Data.DataTable.ReadXml方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET DataTable.ReadXml方法的具體用法?VB.NET DataTable.ReadXml怎麽用?VB.NET DataTable.ReadXml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.ReadXml方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: DemonstrateReadWriteXMLDocumentWithStream
Private Sub DemonstrateReadWriteXMLDocumentWithStream()
Dim table As DataTable = CreateTestTable("XmlDemo")
PrintValues(table, "Original table")
' Write the schema and data to XML in a memory stream.
Dim xmlStream As New System.IO.MemoryStream()
table.WriteXml(xmlStream, XmlWriteMode.WriteSchema)
' Rewind the memory stream.
xmlStream.Position = 0
Dim newTable As New DataTable
newTable.ReadXml(xmlStream)
' Print out values in the table.
PrintValues(newTable, "New Table")
End Sub
Private Function CreateTestTable(ByVal tableName As String) As DataTable
' Create a test DataTable with two columns and a few rows.
Dim table As New DataTable(tableName)
Dim column As New DataColumn("id", GetType(System.Int32))
column.AutoIncrement = True
table.Columns.Add(column)
column = New DataColumn("item", GetType(System.String))
table.Columns.Add(column)
' Add ten rows.
Dim row As DataRow
For i As Integer = 0 To 9
row = table.NewRow()
row("item") = "item " & i
table.Rows.Add(row)
Next i
table.AcceptChanges()
Return table
End Function
Private Sub PrintValues(ByVal table As DataTable, ByVal label As String)
' Display the contents of the supplied DataTable:
Console.WriteLine(label)
For Each row As DataRow In table.Rows
For Each column As DataColumn In table.Columns
Console.Write("{0}{1}", ControlChars.Tab, row(column))
Next column
Console.WriteLine()
Next row
End Sub
示例2: DemonstrateReadWriteXMLDocumentWithReader
Private Sub DemonstrateReadWriteXMLDocumentWithReader()
Dim table As DataTable = CreateTestTable("XmlDemo")
PrintValues(table, "Original table")
' Write the schema and data to XML in a memory stream.
Dim xmlStream As New System.IO.MemoryStream()
table.WriteXml(xmlStream, XmlWriteMode.WriteSchema)
' Rewind the memory stream.
xmlStream.Position = 0
Dim reader As New System.IO.StreamReader(xmlStream)
Dim newTable As New DataTable
newTable.ReadXml(reader)
' Print out values in the table.
PrintValues(newTable, "New Table")
End Sub
Private Function CreateTestTable(ByVal tableName As String) _
As DataTable
' Create a test DataTable with two columns and a few rows.
Dim table As New DataTable(tableName)
Dim column As New DataColumn("id", GetType(System.Int32))
column.AutoIncrement = True
table.Columns.Add(column)
column = New DataColumn("item", GetType(System.String))
table.Columns.Add(column)
' Add ten rows.
Dim row As DataRow
For i As Integer = 0 To 9
row = table.NewRow()
row("item") = "item " & i
table.Rows.Add(row)
Next i
table.AcceptChanges()
Return table
End Function
Private Sub PrintValues(ByVal table As DataTable, _
ByVal label As String)
Console.WriteLine(label)
For Each row As DataRow In table.Rows
For Each column As DataColumn In table.Columns
Console.Write("{0}{1}", ControlChars.Tab, row(column))
Next column
Console.WriteLine()
Next row
End Sub
示例3: DemonstrateReadWriteXMLDocumentWithString
Private Sub DemonstrateReadWriteXMLDocumentWithString()
Dim table As DataTable = CreateTestTable("XmlDemo")
PrintValues(table, "Original table")
' Write the schema and data to XML in a file.
Dim fileName As String = "C:\TestData.xml"
table.WriteXml(fileName, XmlWriteMode.WriteSchema)
Dim newTable As New DataTable
newTable.ReadXml(fileName)
' Print out values in the table.
PrintValues(newTable, "New Table")
End Sub
Private Function CreateTestTable(ByVal tableName As String) _
As DataTable
' Create a test DataTable with two columns and a few rows.
Dim table As New DataTable(tableName)
Dim column As New DataColumn("id", GetType(System.Int32))
column.AutoIncrement = True
table.Columns.Add(column)
column = New DataColumn("item", GetType(System.String))
table.Columns.Add(column)
' Add ten rows.
Dim row As DataRow
For i As Integer = 0 To 9
row = table.NewRow()
row("item") = "item " & i
table.Rows.Add(row)
Next i
table.AcceptChanges()
Return table
End Function
Private Sub PrintValues(ByVal table As DataTable, _
ByVal label As String)
Console.WriteLine(label)
For Each row As DataRow In table.Rows
For Each column As DataColumn In table.Columns
Console.Write("{0}{1}", ControlChars.Tab, row(column))
Next column
Console.WriteLine()
Next row
End Sub
示例4: DemonstrateReadWriteXMLDocumentWithReader
Private Sub DemonstrateReadWriteXMLDocumentWithReader()
Dim table As DataTable = CreateTestTable("XmlDemo")
PrintValues(table, "Original table")
' Write the schema and data to XML in a memory stream.
Dim xmlStream As New System.IO.MemoryStream()
table.WriteXml(xmlStream, XmlWriteMode.WriteSchema)
' Rewind the memory stream.
xmlStream.Position = 0
Dim reader As New System.Xml.XmlTextReader(xmlStream)
Dim newTable As New DataTable
newTable.ReadXml(reader)
' Print out values in the table.
PrintValues(newTable, "New Table")
End Sub
Private Function CreateTestTable(ByVal tableName As String) _
As DataTable
' Create a test DataTable with two columns and a few rows.
Dim table As New DataTable(tableName)
Dim column As New DataColumn("id", GetType(System.Int32))
column.AutoIncrement = True
table.Columns.Add(column)
column = New DataColumn("item", GetType(System.String))
table.Columns.Add(column)
' Add ten rows.
Dim row As DataRow
For i As Integer = 0 To 9
row = table.NewRow()
row("item") = "item " & i
table.Rows.Add(row)
Next i
table.AcceptChanges()
Return table
End Function
Private Sub PrintValues(ByVal table As DataTable, _
ByVal label As String)
Console.WriteLine(label)
For Each row As DataRow In table.Rows
For Each column As DataColumn In table.Columns
Console.Write("{0}{1}", ControlChars.Tab, row(column))
Next column
Console.WriteLine()
Next row
End Sub