How to specify DataRelation with several keys

T

Tony Johansson

Hello!

Below is a DataRelation I have created where we have one primary key on the
parentside which is the Customer
DataRelation custOrderRel = thisDataSet.Relation.Add("custOrders",
thisDataSet.Tables["Customers"].Columns["CustomerID"],
thisDataSet.Tables["Orders"].Columns["CustomerID"]);

Now to my question how do I write a DataRelation if I have a primary key
that consist of two columns.

//Tony
 
C

Chris

Hello!

Below is a DataRelation I have created where we have one primary key on the
parentside which is the Customer
DataRelation custOrderRel = thisDataSet.Relation.Add("custOrders",
thisDataSet.Tables["Customers"].Columns["CustomerID"],
thisDataSet.Tables["Orders"].Columns["CustomerID"]);

Now to my question how do I write a DataRelation if I have a primary key
that consist of two columns.

//Tony

The constructor for the DataRelation class has an overload that takes
an array of DataColumn objects. You should be able to use that.
Something like this: (untested and not complete):

DataRelation dr = new DataRelation("dataRelationName",
new DataColumn[] { thisDataSet.Tables
["parentTableName"].Columns["Column1"],

thisDataSet.Tables["parentTableName"].Columns["Column2"]},
new DataColumn[] { thisDataSet.Tables
["childTableName"].Columns["Column1"],

thisDataSet.Tables["childTableName"].Columns["Column2"]});

Chris
 

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