Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have two tables ,how can i show them together in datagridview?
Posted
Comments
Ziee-M 17-Feb-14 12:35pm    
you can't show 2 table in the same grid. however, you can parse your two table elements objects to same object type, and then put all in a unique datagrid.
Sergey Alexandrovich Kryukov 17-Feb-14 13:19pm    
Same way as one. What's the problem?
—SA

I'm not sure what you mean, but...
DataSource[^] property of DataGridView[^] (DGV) accepts DataTable[^] object. It means you can fetch data from different tables in one query:
SQL
SELECT t1.*, t2.*
FROM t1 INNER JOIN t2 ON t1.key = t2.key


But if you use GridView[^] (ASP.NET) and want to display related records on another GV, please read about nested gridview[^].
 
Share this answer
 
Comments
Member kavyansh 23-Feb-14 7:28am    
ok let me explain again,i have two table not linked with each other as both tables have nothing in common.but at last of all i want is this two tables can represented in datagridview.
just this two tables should be displayed in datagridview.
thank you for helping me out :-)
Maciej Los 23-Feb-14 16:53pm    
It's not possible to display data from 2 tables in the same time in a single Datagridview if they have nothing in common (they're not related).
If both the Tables have same structure, then you can merge them and bind to the DataTable.

Refer answers at load 2 datatables in a datagridview[^].
 
Share this answer
 
Comments
Member kavyansh 23-Feb-14 7:22am    
No,both tables dont have same structure..both tables have different number of columns..so is it still possible to merge them ?
How would you merge? Think of it once. First table have col1, but table don't have col1, but have col2.
How the data will be represented. So, change your logic or requirement,
Member kavyansh 1-Mar-14 12:13pm    
You are correct...i was thinking wrong with respect to logic...absolutely both table should have same structure..
thanks for helping me out.
No problem. Most welcome buddy. Keep coding. :)

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