Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have a table T1 with columns c1,c2,c3 and T2 with c4,c5,c6.
And I want to search from two tables using c2 and c4 from both tables and I want to bind to Gridview.
And I want to display c1,c2,c4,c5 in Gridview.

Can any one tell me the code to bind to Gridview using 2 tables.
Thank you,
Posted
Updated 6-Jun-12 2:25am
v2

you need to merge two table in one,
if you have two table named dtOne and dtTwo this is the code:
C#
dtAll = dtOne.Copy();
dtAll.Merge(dtTwo,true);
 
Share this answer
 
Can any one tell me the code to bind to Gridview using 2 tables.
1. Grid can bind to one table at a time.
2. You need to form a SQL query that fetches the data from the two table
3. Use Foreign Key C1 to combine the two table and get a common result through a single query
4. Use this query result as a data source of your grid.

Now, Try! Post specific issue if you face any.
 
Share this answer
 
Comments
jaipal0908 6-Jun-12 7:51am    
Hi sandeep,
Sorry mistake in question post,There is no relationship is existing between two tables .Then can we bind?
Sandeep Mewara 6-Jun-12 9:15am    
You can only bind grid with one datatable. So, you have to get whole data via query together.
AmitGajjar 6-Jun-12 8:24am    
5+ correct.
Hi,

you can use query something like this.

SQL
select T1.c1,T1.c2,T2.c4,T2.c5 from T1,T2 where T1.c1 = T2.c1 and T1.C2='searchString' and T2.c4='searchString';


Also see the Solution 2 given by Sandeep.

is it what you are looking for ?

Thanks
-Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900