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

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

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".

Ideas?

           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);
            sqlAdapt.Fill(allData);
            testTable = allData.Tables[0];
0
gurteen
Asked:
gurteen
2 Solutions
 
Éric MoreauSenior .Net ConsultantCommented:
Hi gurteen,

Change
> sqlAdapt.Fill(allData);

to
sqlAdapt.Fill(allData, "YourNewTableName");

Cheers!
0
 
GENTPCommented:
also to access the table

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

Featured Post

Industry Leaders: 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