How to bind multiple resultset to a Gridview ? [Resolved]

Posted by Laghaterohan under Regular Expressions on 10/5/2010 | Points: 10 | Views : 10401 | Status : [Member] | Replies : 5
Hello!

I have a S.P. which returns 4 tables in its result set. On my aspx page i have gridview control wherein i need to bind data to the columns from each of these 4 tables. However the problem is i am able to get the columns only in my Table[0] and it cannot find my other columns. How to overcome this issue? If we do use xml how to use it here?

Please suggest.

Here is my sample code :
SqlConnection con = new SqlConnection(" xyz");
string str = "exec spname parameter";
SqlDataAdapter da = new SqlDataAdapter(str,con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds; // This returns only my Table[0] columns which in incorrect, i need to assign datasource which should contain columns from all the 4 tables.
GridView1.DataBind();



Thanks in advance!
Rohan Laghate

Best Regards,
Rohan Laghate



Responses

Posted by: Peermohamedmydeen on: 10/5/2010 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

DataTable dtFinal = new DataTable();


ds.Tables[0]. Merge(ds.Tables[1]);
ds.Tables[0]. Merge(ds.Tables[2]);
ds.Tables[0]. Merge(ds.Tables[3]);

dtFinal = ds.Tables[0];



This will merge all the rows. with additional Columns.

Or else ,

Put a foreach loop for n number of tables.






Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Laghaterohan on: 10/5/2010 [Member] Starter | Points: 25

Up
0
Down
Thanks for the reply...
I shall check it and mark the thread as solved..

Rohan!

Best Regards,
Rohan Laghate

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 10/5/2010 [Member] Bronze | Points: 25

Up
0
Down
you will also get information from this link

http://geekswithblogs.net/shahed/archive/2009/02/11/129310.aspx

LP MER

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kmk008-12044 on: 9/28/2011 [Member] Starter | Points: 25

Up
0
Down
There are two tables
Expenses table and income table
I want to show those two tables in gridview one by one with footer template seperately for each one(i.e for Grand total for each income and expenses seperately). But have to show footertemplate for each table values seperately.
This is my requirement
Please give me suggestion if there is any possibility.....


Thanks and Regards,


Murali Krishna

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kmk008-12044 on: 9/28/2011 [Member] Starter | Points: 25

Up
0
Down
There are two tables
Expenses table and income table
I want to show those two tables in gridview one by one with footer template seperately for each one(i.e for Grand total for each income and expenses seperately).
And how to show footertemplate seperately for each table to calculate total amount in footertemplate seperately for each one.
This is my requirement
Please give me suggestion if there is any possibility.....


Thanks and Regards,

Murali Krishna

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response