How do I add DataTables to a DataSet in ASP.NET 2.0 / C#?

Posted on 2007-07-20
Last Modified: 2010-08-05
I would like to use a DataSet instead of a bunch of scattered DataTables. How do I add DataTables to a DataSet and reference those tables from the DataSet? Here is an example that I'm trying to do:

        DataSet dbTable = new DataSet("Structure");

        DataTable fileTable = new DataTable("Files");
        fileTable.Columns.Add("Name", typeof(String));
        fileTable.Columns.Add("Size", typeof(Double));
        fileTable.Columns.Add("Directory", typeof(Double));

        DataTable directoryTable = new DataTable("Directories");
        directoryTable.Columns.Add("Name", typeof(string));
        directoryTable.Columns.Add("Parent", typeof(string));
        directoryTable.Columns.Add("CreationTime", typeof(DateTime));
Question by:bemara57
    LVL 17

    Accepted Solution

    LVL 29

    Assisted Solution

    by:David H.H.Lee
    Dear bemara57,
    Use this instead:
    DataSet dbTable = new DataSet("Structure");


    dbTable .Tables["Files"] - table "Files"
    dbTable .Tables["Directories"] - table "Directories"

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    734 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

    21 Experts available now in Live!

    Get 1:1 Help Now