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);
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);
if(thisTable ==null){return;}
// For each row in the table, print column 1 of the parent DataRow.
DataRow parentRow;
foreach(DataRow r in thisTable.Rows){
parentRow = r.GetParentRow(relation);
Console.Write("\t child row: " + r[1]);
Console.Write("\t parent row: " + parentRow[1]+ "\n");
}
}
1.传给我的参数只有DataSet
2.我是在静态DataSet中建立的Relation
childCol = DataSet1.Tables["Orders"].Columns["CustID"];
--->>>你的DataSet
DataRelation daR=ds_select.Relations.Add("lkk1",ds_select.Tables["personalInfo"].Columns["id"],ds_select.Tables["Education"].Columns["PersonalInfoid"],false);
//建立DataSet对象中的两个表之间的关联
DataRelation daR=ds_select.Relations.Add("lkk1",ds_select.Tables["Table2"].Columns["A"],ds_select.Tables["Table1"].Columns["B"],false);