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

Who is Participating?
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

Try to set it to nothing

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.