• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2976
  • Last Modified:

DataSet DataRelation

Hi,

I have a problem to build the data relation in DataSet.  
My DataSet contains two datatable.

Table1 has two foriegn key wich is a pair of unique key.  Table 2 has a value plus those two foriegn key.
I only know to build the single primary key mapping to another primarity between two tables.  
SUCH AS ds.Relations.Add("IsellGroup", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0]);
Please help to resolve this problem.  Thank you.
Sample data
table 1
ID1 ID2
1    2
2   2
1   3
2   5

table 2
ID1  ID2 COL
1      2    5
1     2     6
1     3     8
0
power98888
Asked:
power98888
  • 3
1 Solution
 
philipjonathanCommented:
Use DataColumn array:

ds.Relations.Add("IsellGroup",
  new DataColumn[] {ds.Tables[0].Columns[0], ds.Tables[0].Columns[1]},
  new DataColumn[] {ds.Tables[1].Columns[0], ds.Tables[1].Columns[0]}
);
0
 
philipjonathanCommented:
Typo-error in my prev post, my apologies

Use DataColumn array:

ds.Relations.Add("IsellGroup",
  new DataColumn[] {ds.Tables[0].Columns[0], ds.Tables[0].Columns[1]},
  new DataColumn[] {ds.Tables[1].Columns[0], ds.Tables[1].Columns[1]}
);
0
 
power98888Author Commented:
Thank you
0
 
philipjonathanCommented:
Thanks for the generous points
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now