DataAdapter and passing query string question

Discussion in 'ASP .Net' started by stephen, Jun 5, 2008.

  1. stephen

    stephen Guest

    Hi,

    I know that you can pass 2 query strings into a dataadapter and fill a
    dataset with 2 tables like this:

    System.Data.SqlClient.SqlConnection con = new
    System.Data.SqlClient.SqlConnection(Conn);
    System.Data.SqlClient.SqlDataAdapter sda1 =
    new System.Data.SqlClient.SqlDataAdapter("select ShipperID, CompanyName,
    Phone, RegionDescription " +
    "from shippers", con);
    System.Data.SqlClient.SqlDataAdapter sda2 =
    new System.Data.SqlClient.SqlDataAdapter("SELECT EmployeeID, lastname,
    firstname " +
    "FROM Employees", con);
    sda1.Fill(ds, "TableShippers");
    sda2.Fill(ds, "TableEmployees");

    and use it like grid1.datasource = ds.tables["TableShippers"] or
    ds.tables["TableEmployees"]

    ........
    but i came accross an interesting code (pretty sweet...) that instead of 2
    adapters you can pass the 2 queries in the same adapter and it works

    System.Data.SqlClient.SqlConnection con = new
    System.Data.SqlClient.SqlConnection(Conn);
    System.Data.SqlClient.SqlDataAdapter sda =
    new System.Data.SqlClient.SqlDataAdapter("select ShipperID, CompanyName,
    Phone, RegionDescription " +
    "from shippers;" +
    "SELECT EmployeeID, lastname, firstname FROM Employees",
    con);

    if I use it like this grid1.datasource = ds.tables[0] or ds.tables[1] it
    displays the appropriate data but if i use
    ds.tables["TableShippers"] or ds.tables["TableEmployees"] if always binds to
    ds.tables["TableShippers"]

    why? and how can i use it by given table names?

    I tried
    sda.Fill(ds, "TableShippers");
    sda.Fill(ds, "TableEmployees");

    (...felt this syntax is not right but still defaults to shippers....)


    Any ideas,
    Stephen
    stephen, Jun 5, 2008
    #1
    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. Eric A. Johnson

    VB.NET DataAdapter question

    Eric A. Johnson, Oct 17, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    5,040
  2. Paul
    Replies:
    0
    Views:
    639
  3. =?Utf-8?B?am9obiBzbWl0aGVycw==?=

    dataadapter wizard connection string

    =?Utf-8?B?am9obiBzbWl0aGVycw==?=, Sep 5, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    557
    Greg Burns
    Sep 6, 2004
  4. =?Utf-8?B?SklNLkgu?=

    Q: query of dataadapter

    =?Utf-8?B?SklNLkgu?=, Mar 16, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    3,691
    Brock Allen
    Mar 17, 2005
  5. nick
    Replies:
    1
    Views:
    441
    David Mark
    Feb 13, 2011
Loading...

Share This Page