Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 695163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:55:52+00:00 2026-05-14T02:55:52+00:00

I have the code below: string SQL = select * from + TableName; using

  • 0

I have the code below:

string SQL = "select * from " + TableName;

using (DS = new DataSet())
using (SqlDataAdapter adapter = new SqlDataAdapter())
using (SqlConnection sqlconn = new SqlConnection(connectionStringBuilder.ToString()))
using (SqlCommand objCommand = new SqlCommand(SQL, sqlconn))
{
    sqlconn.Open();
    adapter.SelectCommand = objCommand;
    adapter.Fill(DS);
}

System.Windows.Forms.MessageBox.Show(DS.Tables[0].TableName);

return DS;

However, every time I run this code, the dataset (DS) is filled with one table called “Table”. It does not represent the table name I pass in as the parameter TableName and this parameter does not get mutated so I don’t know where the name Table comes from. I’d expect the table to be the same as the tableName parameter I pass in?

Any idea why this is not so?

EDIT: Important fact: This code needs to return a dataset because I use the dataRelation object in another method, which is dependent on this, and without using a dataset, that method throws an exception. The code for that method is:

DataRelation PartToIntersection = new DataRelation("XYZ", 
        this.LoadDataToTable(tableName).Tables[tableName].Columns[0],
        // Treating the PartStat table as the parent - .N
        this.LoadDataToTable("PartProducts").Tables["PartProducts"].Columns[0]);
        // 1

        // PartsProducts (intersection) to ProductMaterial
        DataRelation ProductMaterialToIntersection = 
           new DataRelation("", ds.Tables["ProductMaterial"].Columns[0],
                                ds.Tables["PartsProducts"].Columns[1]);

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:55:52+00:00Added an answer on May 14, 2026 at 2:55 am

    The default name for the first table in the DataSet is Table, the second one will be called Table1 and the third Table2 and so forth. The DataSet will not read the table name from the underlying store – and there’s no option to make it do so.

    This is documented behavior – see the MSDN documentation:

    If the DataAdapter encounters multiple
    result sets, it creates multiple
    tables in the DataSet. The tables are
    given an incremental default name of
    TableN, starting with “Table” for
    Table0.
    If a table name is passed as
    an argument to the Fill method, the
    tables are given an incremental
    default name of TableNameN, starting
    with “TableName” for TableName0.

    If you want other names, you have to supply those – use this statement:

    adapter.Fill(DS, Tablename);
    

    This will name the newly filled table Tablename inside the DataSet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have strings formatted using the code below String.Format({0,-10} {1,10}, Kills:, kills); String.Format({0,-10} {1,10},
Please have a look at the code below: import string from collections import defaultdict
I have below code snippet SimpleDateFormat dateFormat = new SimpleDateFormat( yyyy-MM-dd hh:mm:ss.SSS); String processedContentDate=2012-04-10
I have code as below: var s : String = hello world var xml
I have below code: class Program { static void Main(string[] args) { Task[] tasks
I have the below code: public void OpenFile(string FileName) { if (FileName == null)
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I'm using MVC3 with C# code. I have a table in my SQL Server
I have the below code that splits the sql statement and give its indices
I have this code UPDATE OPENQUERY (db,'SELECT * FROM table WHERE ref = ''+

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.