Create DataSet relation with more than 1 field

T

Tim Kelley

I have two tables that are linked by 2 fields (ID1 and ID2). Is it possible
to create this relation once the tables are in a DataSet? I can create a
relation using a single field, but I don't know if this is possible with
multiple fields.

Thanks,
 
K

Karthik D V

Tim said:
I have two tables that are linked by 2 fields (ID1 and ID2). Is it possible
to create this relation once the tables are in a DataSet? I can create a
relation using a single field, but I don't know if this is possible with
multiple fields.

Thanks,

Hi,
This is how you can do .... I have given code snippet. I think
this will be useful for your problem.

DataSet ds;
DataTable dt1;
DataTable dt2;
ds.Tables.Add(dt1);
ds.Tables.Add(dt2);
DataRelation dr1 = new DataRelation("ID1 RELATION",
"PARENTID1", "CHILDID1");
dr1.ParentTable = dt1;
dr1.ChildTable = dt2;
DataRelation dr2 = new DataRelation("ID2 RELATION",
"PARENTID2", "CHILDID2");
dr2.ParentTable = dt1;
dr2.ChildTable = dt2;
ds.Relations.Add(dr2);
 

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