Click here to Skip to main content
15,906,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to connect a gridview to two or more tables at the same time ? Please give me a solution. thank you in advance
Posted

This [^]discussion could help you.
 
Share this answer
 
If you bind to a table with relationships, you get drill-down capabilities. Is that what you want?

You can also bind to a view, if you're binding to a database, which allows you to collect data from several tables.

To include data for two or more tables you need to define how they get merged into one list, and to the same data type. That means you need to write your own data binding source (inheriting from IBindingList, BindingSource or something similar). A word of warning, getting a DataGridView to behave properly with a custom data binding source class is a bit of a pain.
 
Share this answer
 
You can't connect it to two tables, but you could create a view consisting of as many tables as you wish, and connect your gridview to that. Depending on your ORM, you're looking at creating some sort of data object for the view, be it an ADO.net DataSet/DataTable, Entity Model, POCO Template or whatever. Then you can just databind as with a normal table.
 
Share this answer
 
 
Share this answer
 
it will be better for you to create view in database and return

data by join two tables and bind that to your gridview

SQL
CREATE VIEW ViewName AS
SELECT Table1.* ,Tabl2.* FROM  Table1 RIGHT OUTER JOIN Table2
on Table1.Col = Table2.Col
 
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