mutliple tables in datagrid

G

Guest

Hi,

I'm wondering if it is possible to display in a datagrid multiple columns
coming from 2 different tables without having to do the a join in my sql
statement.
For example, I create 2 data adapters, each doing a select on a specific
table. I fill them both in the same dataset. Now, I would like to display in
the same time some of the columns from the first table, and some of the
second. Luckily, there is a relation between the two tables. So, it's a sort
of a Master / Detail display on the same grid. I tried tableStyles along with
columnStyles but I couldn't get the datagrid to display the columns I need.

Is there a way to do it?

Thanks
 
M

Miha Markic [MVP C#]

Hi,

No, there is no easy way.
If you have only to display data you might consider loading it using JOIN
statement.
 
G

Grzegorz Danowski

U¿ytkownik "jy said:
Hi,

I'm wondering if it is possible to display in a datagrid multiple columns
coming from 2 different tables without having to do the a join in my sql
statement.
For example, I create 2 data adapters, each doing a select on a specific
table. I fill them both in the same dataset. Now, I would like to display
in
the same time some of the columns from the first table, and some of the
second. Luckily, there is a relation between the two tables. So, it's a
sort
of a Master / Detail display on the same grid. I tried tableStyles along
with
columnStyles but I couldn't get the datagrid to display the columns I
need.


Ycan use Expression column, for example:

ds.Tables["titleauthor"].Columns.Add("title", typeof(string),
"Parent(titles_titleauthor).title");

Regards,
Grzegorz
 
E

Earl

Here is a snippet from one of my apps. Notice that dtOilCompanies is the
child table and dtOilCompanyZips is the parent. Add columns from the parent
to the child, then use the child table as datasource for the grid. (I may
have learned this from the Sceppa book, or it might have come directly from
one of the 'Softies.) Be advised that your insert and update logic gets a
little trickier using this technique.

rel = New DataRelation("ZipCityState_OilCompanies", _
ds.Tables("dtOilCompanyZips").Columns("ZipCityStateID"), _
ds.Tables("dtOilCompanies").Columns("ZipCityStateID"), False)
ds.Relations.Add(rel)

ds.Tables("dtOilCompanies").Columns.Add("City", GetType(String),
"Parent(ZipCityState_OilCompanies).City")
ds.Tables("dtOilCompanies").Columns.Add("State", GetType(String),
"Parent(ZipCityState_OilCompanies).State")
ds.Tables("dtOilCompanies").Columns.Add("Zip", GetType(String),
"Parent(ZipCityState_OilCompanies).Zip")

DataGrid1.DataSource = ds.Tables("dtOilCompanies")
cm = CType(Me.BindingContext(ds.Tables("dtOilCompanies")),
CurrencyManager)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top