When I Fill a DataSet, Can I control the string names of the tables?

Posted on 2006-04-21
Last Modified: 2010-04-16
I would like to be able to access the table from my DataSet using either
(a) a name I specify or
(b) the name of the table the data is coming from

but for some reason C# 2005 is defaulting me to "Table".


           DataTable testTable = new DataTable("MYTABLE");
            DataSet allData = new DataSet("allData");

            //Why does this come back as "Table" instead of FCDET?
            SqlCommand sqlCommand = new SqlCommand("SELECT * from FCDET;", conn);
            SqlDataAdapter sqlAdapt = new SqlDataAdapter(sqlCommand);

            sqlAdapt.FillSchema(allData, SchemaType.Source);
            testTable = allData.Tables[0];
Question by:gurteen
    LVL 69

    Accepted Solution

    Hi gurteen,

    > sqlAdapt.Fill(allData);

    sqlAdapt.Fill(allData, "YourNewTableName");

    LVL 5

    Assisted Solution

    also to access the table

    DataTable myDataTable = allData.Tables["YourNewTableName"];

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    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…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now