delete datatable in dataset

Posted on 2007-07-19
Last Modified: 2007-07-20
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

Question by:Marcusw
    LVL 15

    Expert Comment

    Try to set it to nothing

    set ds = nothing

    Author Comment

    i need to keep the dataset i just need to delete the table.

    LVL 14

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now