本文整理汇总了VB.NET中System.Data.DataView.ToTable方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DataView.ToTable方法的具体用法?VB.NET DataView.ToTable怎么用?VB.NET DataView.ToTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataView
的用法示例。
在下文中一共展示了DataView.ToTable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: DemonstrateDataView
Private Sub DemonstrateDataView()
' Create a DataTable with three columns.
Dim table As New DataTable("NewTable")
Console.WriteLine("Original table name: " & table.TableName)
Dim column As New DataColumn("ID", GetType(System.Int32))
table.Columns.Add(column)
column = New DataColumn("Category", GetType(System.String))
table.Columns.Add(column)
column = New DataColumn("Product", GetType(System.String))
table.Columns.Add(column)
column = New DataColumn("QuantityInStock", GetType(System.Int32))
table.Columns.Add(column)
' Add some items.
Dim row As DataRow = table.NewRow()
row.ItemArray = New Object() {1, "Fruit", "Apple", 14}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {2, "Fruit", "Orange", 27}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {3, "Bread", "Muffin", 23}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {4, "Fish", "Salmon", 12}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {5, "Fish", "Salmon", 15}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {6, "Bread", "Croissant", 23}
table.Rows.Add(row)
' Mark all rows as "accepted". Not required
' for this particular example.
table.AcceptChanges()
' Print current table values.
PrintTableOrView(table, "Current Values in Table")
Dim view As New DataView(table)
view.Sort = "Category"
PrintTableOrView(view, "Current Values in View")
Dim newTable As DataTable = view.ToTable( _
True, "Category", "QuantityInStock")
PrintTableOrView(newTable, "Table created from sorted DataView")
Console.WriteLine("New table name: " & newTable.TableName)
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Sub PrintTableOrView(ByVal dv As DataView, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Dim table As DataTable = dv.Table
Console.WriteLine(label)
' Loop through each row in the view.
For Each rowView As DataRowView In dv
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(rowView(col.ColumnName).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub
Private Sub PrintTableOrView(ByVal table As DataTable, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Console.WriteLine(label)
' Loop through each row in the table.
For Each row As DataRow In table.Rows
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(row(col).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub
示例2: DemonstrateDataView
Private Sub DemonstrateDataView()
' Create a DataTable with three columns.
Dim table As New DataTable("NewTable")
Console.WriteLine("Original table name: " & table.TableName)
Dim column As New DataColumn("ID", GetType(System.Int32))
table.Columns.Add(column)
column = New DataColumn("Category", GetType(System.String))
table.Columns.Add(column)
column = New DataColumn("Product", GetType(System.String))
table.Columns.Add(column)
column = New DataColumn("QuantityInStock", GetType(System.Int32))
table.Columns.Add(column)
' Add some items.
Dim row As DataRow = table.NewRow()
row.ItemArray = New Object() {1, "Fruit", "Apple", 14}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {2, "Fruit", "Orange", 27}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {3, "Bread", "Muffin", 23}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {4, "Fish", "Salmon", 12}
table.Rows.Add(row)
' Mark all rows as "accepted". Not required
' for this particular example.
table.AcceptChanges()
' Print current table values.
PrintTableOrView(table, "Current Values in Table")
Dim view As New DataView(table)
view.RowFilter = "QuantityInStock > 15"
PrintTableOrView(view, "Current Values in View")
Dim newTable As DataTable = view.ToTable("FilteredTable")
PrintTableOrView(newTable, "Table created from filtered DataView")
Console.WriteLine("New table name: " & newTable.TableName)
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Sub PrintTableOrView(ByVal dv As DataView, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Dim table As DataTable = dv.Table
Console.WriteLine(label)
' Loop through each row in the view.
For Each rowView As DataRowView In dv
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(rowView(col.ColumnName).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub
Private Sub PrintTableOrView(ByVal table As DataTable, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Console.WriteLine(label)
' Loop through each row in the table.
For Each row As DataRow In table.Rows
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(row(col).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub
示例3: DemonstrateDataView
Private Sub DemonstrateDataView()
' Create a DataTable with three columns.
Dim table As New DataTable("NewTable")
Console.WriteLine("Original table name: " & table.TableName)
Dim column As New DataColumn("ID", GetType(System.Int32))
table.Columns.Add(column)
column = New DataColumn("Category", GetType(System.String))
table.Columns.Add(column)
column = New DataColumn("Product", GetType(System.String))
table.Columns.Add(column)
column = New DataColumn("QuantityInStock", GetType(System.Int32))
table.Columns.Add(column)
' Add some items.
Dim row As DataRow = table.NewRow()
row.ItemArray = New Object() {1, "Fruit", "Apple", 14}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {2, "Fruit", "Orange", 27}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {3, "Bread", "Muffin", 23}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {4, "Fish", "Salmon", 12}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {5, "Fish", "Salmon", 15}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {6, "Bread", "Croissant", 23}
table.Rows.Add(row)
' Mark all rows as "accepted". Not required
' for this particular example.
table.AcceptChanges()
' Print current table values.
PrintTableOrView(table, "Current Values in Table")
Dim view As New DataView(table)
view.Sort = "Category"
PrintTableOrView(view, "Current Values in View")
Dim newTable As DataTable = view.ToTable("UniqueData", _
True, "Category", "QuantityInStock")
PrintTableOrView(newTable, "Table created from sorted DataView")
Console.WriteLine("New table name: " & newTable.TableName)
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Sub PrintTableOrView(ByVal dv As DataView, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Dim table As DataTable = dv.Table
Console.WriteLine(label)
' Loop through each row in the view.
For Each rowView As DataRowView In dv
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(rowView(col.ColumnName).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub
Private Sub PrintTableOrView(ByVal table As DataTable, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Console.WriteLine(label)
' Loop through each row in the table.
For Each row As DataRow In table.Rows
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(row(col).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub
示例4: DemonstrateDataView
Private Sub DemonstrateDataView()
' Create a DataTable with three columns.
Dim table As New DataTable("NewTable")
Console.WriteLine("Original table name: " & table.TableName)
Dim column As New DataColumn("ID", GetType(System.Int32))
table.Columns.Add(column)
column = New DataColumn("Category", GetType(System.String))
table.Columns.Add(column)
column = New DataColumn("Product", GetType(System.String))
table.Columns.Add(column)
column = New DataColumn("QuantityInStock", GetType(System.Int32))
table.Columns.Add(column)
' Add some items.
Dim row As DataRow = table.NewRow()
row.ItemArray = New Object() {1, "Fruit", "Apple", 14}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {2, "Fruit", "Orange", 27}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {3, "Bread", "Muffin", 23}
table.Rows.Add(row)
row = table.NewRow()
row.ItemArray = New Object() {4, "Fish", "Salmon", 12}
table.Rows.Add(row)
' Mark all rows as "accepted". Not required
' for this particular example.
table.AcceptChanges()
' Print current table values.
PrintTableOrView(table, "Current Values in Table")
Dim view As New DataView(table)
view.RowFilter = "QuantityInStock > 15"
PrintTableOrView(view, "Current Values in View")
Dim newTable As DataTable = view.ToTable()
PrintTableOrView(newTable, "Table created from filtered DataView")
Console.WriteLine("New table name: " & newTable.TableName)
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Sub PrintTableOrView(ByVal dv As DataView, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Dim table As DataTable = dv.Table
Console.WriteLine(label)
' Loop through each row in the view.
For Each rowView As DataRowView In dv
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(rowView(col.ColumnName).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub
Private Sub PrintTableOrView(ByVal table As DataTable, ByVal label As String)
Dim sw As System.IO.StringWriter
Dim output As String
Console.WriteLine(label)
' Loop through each row in the table.
For Each row As DataRow In table.Rows
sw = New System.IO.StringWriter
' Loop through each column.
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
sw.Write(row(col).ToString() & ", ")
Next
output = sw.ToString
' Trim off the trailing ", ", so the output looks correct.
If output.Length > 2 Then
output = output.Substring(0, output.Length - 2)
End If
' Display the row in the console window.
Console.WriteLine(output)
Next
Console.WriteLine()
End Sub