Home All Groups Group Topic Archive Search About

Displaying data from 2 tables in one datagridview

Author
25 Apr 2006 8:53 AM
Lars E.
Hi all.

i am trying to display contents from 2 tables in one datagridview.

It is not possible for me to do a join, so i have to combine 2 datatables to be able to show data from both tables.

My tables are: "Customer" and "Customer Contact".

The relation is: Customer.c-Customerno = CustomerContract.cc-Customerno  (the primary key names are not the same)

I want to display customers with the customers contact information.

Do i have to create a new datatable and populate this from det different tables in my dataset.
(ds.tables[0] and ds.tables[1]).

How can i do this. Please help.

Author
25 Apr 2006 8:59 AM
Cor Ligthert [MVP]
Lars,

As you said, see here a sample from it on our website.

http://www.vb-tips.com/default.aspx?ID=5fd5a8cf-54dc-4946-a193-8a9529b2b38b

I hope this helps,

Cor

Show quote
<Lars E.> schreef in bericht news:%23ZcQ8WEaGHA.4144@TK2MSFTNGP04.phx.gbl...
> Hi all.
>
> i am trying to display contents from 2 tables in one datagridview.
>
> It is not possible for me to do a join, so i have to combine 2 datatables
> to be able to show data from both tables.
>
> My tables are: "Customer" and "Customer Contact".
>
> The relation is: Customer.c-Customerno = CustomerContract.cc-Customerno
> (the primary key names are not the same)
>
> I want to display customers with the customers contact information.
>
> Do i have to create a new datatable and populate this from det different
> tables in my dataset.
> (ds.tables[0] and ds.tables[1]).
>
> How can i do this. Please help.
>
Author
25 Apr 2006 9:29 AM
Lars E
Thanks, but that link was to VB-Help.

Perhaps i made a request in the wrong newsgroup.

I am trying to do this in C#.
Should i use another newsgroup?

Lars E.
Author
25 Apr 2006 1:39 PM
Cor Ligthert [MVP]
So much difference is there not between VBNet and C#

To take the main solution in the sample

\\\
ds.Relations.Add("MyRelation", dt1.Columns["TheRelation"],
dt2.Columns["TheRelation"]);
dt2.Columns.Add("State", Type.GetType("System.String"), "Parent.State");
DataGridView1.DataSource = dt2;
///
Roughly done,

Cor

AddThis Social Bookmark Button