How to display result from two different table

V

vasu

Hi all

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


Thanks in adavance

vasu
 
A

Alvin Bruney

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
 
T

Todd

vasu said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top