[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1195
  • Last Modified:

delete datatable in dataset

hope fully an easy one

i have a datatable in my dataset


i would like to comletely delete it, but cannot seem to work out how, i have tired dispose and reset but i am getting nowhere

the table is frequently refilled with different number.and names of columns, so i think this i my only alternative

1 Solution
Try to set it to nothing

set ds = nothing
MarcuswAuthor Commented:
i need to keep the dataset i just need to delete the table.

Public Sub DataTableCollectionCanRemove()
        ' create a DataSet with two tables
        Dim myDataSet As DataSet = New DataSet
        ' create Customer table
        Dim t As DataTable = New DataTable("Customers")
        t.Columns.Add("customerId", GetType(System.Int32)).AutoIncrement = true
        t.Columns.Add("name", GetType(System.String))
        t.PrimaryKey = New DataColumn() {t.Columns("customerId")}
        ' create Orders table
        Dim t2 As DataTable = New DataTable("Orders")
        t2.Columns.Add("orderId", GetType(System.Int32)).AutoIncrement = true
        t2.Columns.Add("customerId", GetType(System.Int32))
        t2.Columns.Add("amount", GetType(System.Double))
        t2.PrimaryKey = New DataColumn() {t.Columns("orderId")}
        myDataSet.Tables.AddRange(New DataTable() {t, t2})
        ' remove all tables
        ' check if table can be removed and then
        ' remove it, cannot use a foreach when
        ' removing items from a collection
        While (myDataSet.Tables.Count > 0)
            Dim table As DataTable = myDataSet.Tables(0)
            If myDataSet.Tables.CanRemove(table) Then
            End If
        End While
        Console.WriteLine("myDataSet has {0} tables", myDataSet.Tables.Count)
    End Sub


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now