dataset table name

Discussion in 'ASP .Net' started by Antonio, May 26, 2006.

  1. Antonio

    Antonio Guest

    hi i working whit ado.net2.0 have fill 3 data table to my dataset using
    this code

    Dim qry1 As String = "SELECT * FROM Employees;SELECT * FROM
    Customers;SELECT * FROM Orders"
    Dim da1 As New Data.SqlClient.SqlDataAdapter(qry1, cn)
    da1.Fill(ds)
    my question is :
    can i set name of my dataset's table? now i recive table, table1,
    table2

    Regard

    Antonio F.
    Antonio, May 26, 2006
    #1
    1. Advertising

  2. Antonio

    Rob Meade Guest

    "Antonio" wrote ..

    > hi i working whit ado.net2.0 have fill 3 data table to my dataset using
    > this code
    >
    > Dim qry1 As String = "SELECT * FROM Employees;SELECT * FROM
    > Customers;SELECT * FROM Orders"
    > Dim da1 As New Data.SqlClient.SqlDataAdapter(qry1, cn)
    > da1.Fill(ds)
    > my question is :
    > can i set name of my dataset's table? now i recive table, table1,
    > table2


    Hi Antonio,

    I'm sure someone else will have a better answer, but I've managed to set the
    names before, but based on a hard coded solution, rather than dynamically
    from the SQL statement, ie...

    Something like (and forgive me if this isn't 100% syntactically correct -
    its been a while) -

    DataSet.DataTable(0).Name = "Fred"
    DataSet.DataTable(1).Name = "Barney"

    But this would of course assume that you would always populate the dataset
    in the same order etc..

    Sorry if this isn't a whole lot of help.

    Regards

    Rob
    Rob Meade, May 26, 2006
    #2
    1. Advertising

  3. Antonio

    Kuldeep Guest

    Hello Antonio,

    While retrieving data from the dataset,
    cant we try giving
    objDs.Tables[0].Rows[0]["column_name"].ToString().Trim();

    objDs.Tables[0].Rows[1]["column_name"].ToString().Trim();

    objDs.Tables[0].Rows[2]["column_name"].ToString().Trim();

    where in 0,1,2 would represent 3 different tables of the same dataset objDs

    Hope this would help you!

    Regards
    Kuldeep

    "Antonio" <> wrote in message
    news:...
    > hi i working whit ado.net2.0 have fill 3 data table to my dataset using
    > this code
    >
    > Dim qry1 As String = "SELECT * FROM Employees;SELECT * FROM
    > Customers;SELECT * FROM Orders"
    > Dim da1 As New Data.SqlClient.SqlDataAdapter(qry1, cn)
    > da1.Fill(ds)
    > my question is :
    > can i set name of my dataset's table? now i recive table, table1,
    > table2
    >
    > Regard
    >
    > Antonio F.
    >
    Kuldeep, May 26, 2006
    #3
  4. ....or you could use table mappings:

    myDataAdapter.TableMappings.Add("Table1", "Orders");
    myDataAdapter.TableMappings.Add("Table2", "OrderDetails");
    myDataAdapter.Fill(myDataSet);

    "Antonio" <> wrote in message
    news:...
    > hi i working whit ado.net2.0 have fill 3 data table to my dataset using
    > this code
    >
    > Dim qry1 As String = "SELECT * FROM Employees;SELECT * FROM
    > Customers;SELECT * FROM Orders"
    > Dim da1 As New Data.SqlClient.SqlDataAdapter(qry1, cn)
    > da1.Fill(ds)
    > my question is :
    > can i set name of my dataset's table? now i recive table, table1,
    > table2
    >
    > Regard
    >
    > Antonio F.
    >
    Mark Newmister, May 26, 2006
    #4
  5. Antonio

    embuhrow

    Joined:
    Jul 3, 2008
    Messages:
    1
    For those looking to just rename the tables in a DataSet, I found that the easiest way to go about doing this is the following.

    string[] tables = { "myTable1", "myTable2", "myTable3" };
    DataSet ds = new DataSet
    string sqlStatement = "SELECT * FROM Table1; SELECT * FROM Table2; SELECT * FROM Table3";
    SqlDataAdapter da = new SqlDataAdapter(sqlStatement, connection);
    da.Fill(ds);

    for (int index = 0; index < ds.Tables.Count; index++)
    {
    ds.Tables[index].TableName = tables[index];
    }
    embuhrow, Jul 3, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nedu N
    Replies:
    1
    Views:
    1,792
    Chris Taylor
    Oct 31, 2003
  2. Nedu N
    Replies:
    2
    Views:
    2,151
  3. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    819
    Roedy Green
    Jan 2, 2006
  4. donet programmer
    Replies:
    1
    Views:
    510
    donet programmer
    Dec 5, 2006
  5. Nedu N
    Replies:
    2
    Views:
    219
    Jacob Yang [MSFT]
    Oct 31, 2003
Loading...

Share This Page