locked
Change DataSet table names RRS feed

  • Question

  • User1909955381 posted

    I have a stored procedure that has several select statements.  I'm using a dataadapter to run the query, and then fill a dataset.  When I try and access the multiple tables in the dataset, they are named "Table", "Table1", "Table2", etc.  How can I change that?

    Monday, June 16, 2008 1:53 PM

Answers

  • User1325285552 posted

    Do this: 

    dataAdapter.Fill(dataset,"YourTableName");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 16, 2008 2:04 PM
  • User1325285552 posted

    If you want to do this after you have filled then you can also do this:

    dataset.Tables[0].TableName = "MyTable1";

    dataset.Tables[1].TableName = "MyTable2";

    or do it in loop

    for (int i = 0; i <= dataset.Tables.Count; i++)

    {

    dataset.Tables[i].TableName =
    "MyTable" + i.ToString();

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 16, 2008 2:55 PM

All replies

  • User1325285552 posted

    Do this: 

    dataAdapter.Fill(dataset,"YourTableName");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 16, 2008 2:04 PM
  • User1909955381 posted

    Do this: 

    dataAdapter.Fill(dataset,"YourTableName");

     

    The only problem is that there are multiple tables within the dataset.  That will change the table name for only one table.  How can I change them all?

    Monday, June 16, 2008 2:09 PM
  • User1325285552 posted

    If you want to do this after you have filled then you can also do this:

    dataset.Tables[0].TableName = "MyTable1";

    dataset.Tables[1].TableName = "MyTable2";

    or do it in loop

    for (int i = 0; i <= dataset.Tables.Count; i++)

    {

    dataset.Tables[i].TableName =
    "MyTable" + i.ToString();

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 16, 2008 2:55 PM
  • User1909955381 posted

    Thanks 

    Wednesday, June 18, 2008 5:56 PM