本文整理汇总了VB.NET中System.Data.DataTableCollection.Remove方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DataTableCollection.Remove方法的具体用法?VB.NET DataTableCollection.Remove怎么用?VB.NET DataTableCollection.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataTableCollection
的用法示例。
在下文中一共展示了DataTableCollection.Remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: RemoveTables
Private Sub RemoveTables()
' Set the name of the table to test for and remove.
Dim name As String = "Suppliers"
' Presuming a DataGrid is displaying more than one table, get its DataSet.
Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)
Dim tablesCol As DataTableCollection = thisDataSet.Tables
If tablesCol.Contains(name) _
And tablesCol.CanRemove(tablesCol(name)) Then
tablesCol.Remove(name)
End If
End Sub
示例2: Main
Public Sub Main
DataTableCollectionCanRemove
End Sub
Public Sub DataTableCollectionCanRemove()
' create a DataSet with two tables
Dim dataSet As New DataSet()
' create Customer table
Dim customersTable As New DataTable("Customers")
customersTable.Columns.Add("customerId", _
System.Type.GetType("System.Integer")).AutoIncrement = True
customersTable.Columns.Add("name", _
System.Type.GetType("System.String"))
customersTable.PrimaryKey = New DataColumn() _
{customersTable.Columns("customerId")}
' create Orders table
Dim ordersTable As New DataTable("Orders")
ordersTable.Columns.Add("orderId", _
System.Type.GetType("System.Integer")).AutoIncrement = True
ordersTable.Columns.Add("customerId", _
System.Type.GetType("System.Integer"))
ordersTable.Columns.Add("amount", _
System.Type.GetType("System.Double"))
ordersTable.PrimaryKey = New DataColumn() _
{ordersTable.Columns("orderId")}
dataSet.Tables.AddRange(New DataTable() {customersTable, ordersTable})
' remove all tables
' check if table can be removed and then
' remove it, cannot use a foreach when
' removing items from a collection
Do While (dataSet.Tables.Count > 0)
Dim table As DataTable = dataSet.Tables(0)
If (dataSet.Tables.CanRemove(table)) Then
dataSet.Tables.Remove(table)
End If
Loop
Console.WriteLine("dataSet has {0} tables", dataSet.Tables.Count)
End Sub