How to display result from two different table

Discussion in 'ASP .Net Datagrid Control' started by vasu, Nov 20, 2003.

  1. vasu

    vasu Guest

    Hi all

    Iam in a problem. Anyone plz help me in retreving data into single
    datagrid from two different queries.


    Thanks in adavance

    vasu
     
    vasu, Nov 20, 2003
    #1
    1. Advertising

  2. vasu

    Alvin Bruney Guest

    The problem is that binding can only occur on a single datasource. You will
    need to take these two datasets which you get returned from the two
    different queries and merge them into one dataset then bind to this
    aggregate dataset. You may be able to use the merge function exposed by the
    dataset or you may want to create a new dataset, attach a new table to it
    and manually add rows from both datasets into this one datatable. once you
    are done, you can bind to this new dataset. Either approach should bring you
    the required results.

    Here is some code to help you with the lata if you choose to go thru it

    DataSet dsTemp = new DataSet();

    DataTable Tables = new DataTable();

    dsTemp.Tables.Add(Tables);

    dsTemp.Tables[0].Columns.Add( " ", System.Type.GetType( "System.String" ) );

    dsTemp.Tables[0].Columns.Add( "% variance", System.Type.GetType(
    "System.String" ) );



    for(int col = 0; col < ds.Tables[0].Columns.Count; col++)

    {

    DataRow myRow = dsTemp.Tables[0].NewRow();

    myRow[2]= Double.Parse(ds.Tables[0].Rows[0][col].ToString()) -
    Double.Parse(ds2.Tables[0].Rows[0][col].ToString());

    myRow[1]= (Double.Parse(myRow[2].ToString()) /
    Double.Parse(ds2.Tables[0].Rows[0][col].ToString())) * 100;

    myRow[0]= ds.Tables[0].Columns[col].ColumnName;


    dsTemp.Tables[0].Rows.Add(myRow);



    This will point you down the right direction.

    Regards
    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    "vasu" <> wrote in message
    news:...
    > Hi all
    >
    > Iam in a problem. Anyone plz help me in retreving data into single
    > datagrid from two different queries.
    >
    >
    > Thanks in adavance
    >
    > vasu
    >
    >
     
    Alvin Bruney, Nov 21, 2003
    #2
    1. Advertising

  3. vasu

    Todd Guest

    "vasu" <> wrote in message news:<>...
    > Hi all
    >
    > Iam in a problem. Anyone plz help me in retreving data into single
    > datagrid from two different queries.
    >
    >
    > Thanks in adavance
    >
    > vasu

    Is it possible to join the two queries into one? Use an "Inner Join".
    If two seperate tables have a like column in each that can link to
    each other, then you can use that like value to create a join of the
    two tables. For example, if you are pulling "names" from one table in
    your first query, and then "locations" from another table in your
    second query, would you somehow be able to join the two tables on a
    like value and run one query to create one dataset? Let's say that
    each table has a column named "IDNumber" that represents a unique
    number for a certain person on both tables. Example:

    SELECT
    Names.Firstname,
    Names.LastName,
    Locations.PrimaryOffice,
    Locations.AlternateOffice
    FROM
    Names INNER JOIN Locations ON Names.IDNumber = Locations.IDNumber
    order by Names.LastName

    Then all you would need to do is set the source and bind that single
    dataset to the control.
     
    Todd, Nov 24, 2003
    #3
    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. Tao Wang
    Replies:
    4
    Views:
    338
    Tao Wang
    Nov 9, 2005
  2. nani
    Replies:
    2
    Views:
    383
    bruce barker
    Jun 17, 2007
  3. Christopher Brewster
    Replies:
    5
    Views:
    360
    John Machin
    Nov 14, 2008
  4. Michael Tan
    Replies:
    32
    Views:
    1,049
    Ara.T.Howard
    Jul 21, 2005
  5. denmat
    Replies:
    2
    Views:
    182
    denmat
    Apr 23, 2008
Loading...

Share This Page