Data Relations

  • Thread starter Thread starter Ken
  • Start date Start date
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.
 
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);
 
Back
Top