?
Solved

Binding gridview to two datasources

Posted on 2007-10-01
10
Medium Priority
?
4,710 Views
Last Modified: 2013-11-26
I think this is easy but my brain hurts :( i want to bind a gridview to two different datasources, i am thinking that the best way to do this is to create a new datatable and add both datatables  to the one and bind it to the grid. but i am having problems getting this to work. any ideas  on how to do this and if maybe there is a better solution than doing it this way?
0
Comment
Question by:Steege1
8 Comments
 
LVL 13

Expert Comment

by:dungla
ID: 19996083
Why do you need to bind two datasources to the gridview?
0
 

Author Comment

by:Steege1
ID: 19996191
i have two different datatables that i want to merge for one view, i could put them into seperate views but that doesnt make sense  since the data is very similar. its coming from the same database but different parameters and i really dont want to create a sproc just for this one special occasion. so i figure my best bet would be two make my sproc call that returns the datatables. put them into one and then bind. like i said im not sure if this is the best solution, i.e. putting the two datatables together or if there is a way you can databind of gridview to two differenct sourcs
0
 
LVL 7

Expert Comment

by:Abu Hamdan
ID: 19996448
Hi,

You can combine the 2 results you are getting from DB using queries, you said you have 2 quesries each one on same table but with different paramaters,, so you can do the following:

select * from myTable where column1 = par1 and column2= par1
union
select * from myTable where column1 = par3 and column2= par4


This will return 2 results combined with one DataTable
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Steege1
ID: 19998522
i am using sp calls so i would prefer not to make a wrapper sp for this
0
 
LVL 7

Expert Comment

by:Abu Hamdan
ID: 20001039
Okay another way ,, is to make you own datatable,, make new datatable add whatever columns to it ,, then bind it by looping through the results from 2 sp,,
0
 

Author Comment

by:Steege1
ID: 20001056
do you have any code examples? i understand that this is what i want to do but need a start on how
0
 
LVL 7

Accepted Solution

by:
Abu Hamdan earned 500 total points
ID: 20001111
DataSet ds = new DataSet();

ds.Tables.Add("myTable");  

dsPort.Tables[0].Columns.Add("column1");
dsPort.Tables[0].Columns.Add("qty",System.Type.GetType("System.Decimal"));

// Loop through result1
while (drPort.Read())
{            
DataRow oRow = ds.Tables[0].NewRow();  
oRow["column1"]= drPort["resul1"];
oRow["column2"]= drPort["resul2"];
}
                                    
and repeat same for second result ,, looping is regular datareader
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20237484
Forced accept.

Computer101
EE Admin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question