Data Relations

K

Ken

Has anyone created a data relation that consists of two concatenated fields
for parentCol and childCol instead of one as in this Miscrsoft example in
C#?

private void CreateRelation() {
// Get the DataColumn objects from two DataTable objects in a DataSet.
DataColumn parentCol;
DataColumn childCol;
// Code to get the DataSet not shown here.
parentCol = DataSet1.Tables["Customers"].Columns["CustID"];
childCol = DataSet1.Tables["Orders"].Columns["CustID"];
// Create DataRelation.
DataRelation relCustOrder;
relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol);
// Add the relation to the DataSet.
DataSet1.Relations.Add(relCustOrder);
}


I posted this in another forum by accident.
 
B

Burton Roberts

Why concatenate the fields? Just define the parent and child as datacolumn
arrays and, assign the columns to the appropriate array members. (I'm a VB
guy, so excuse if I make a silly error)

DataColumn[] parentCol;
DataColumn[] childCol;

parentCol[0] = DataSet1.Tables["Customers"].Columns["CustID"];
parentCol[1] = DataSet1.Tables["Customers"].Columns["OtherColumn"];

childCol[0] = DataSet1.Tables["Orders"].Columns["CustID"];
childCol[1] = DataSet1.Tables["Orders"].Columns["OtherColumn"];
DataRelation relCustOrder;
relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol);
DataSet1.Relations.Add(relCustOrder);
 

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