2009-12-10 41 views

回答

1

如果可以,首先從SQL JOIN語句生成數據表。這將顯着更高效。

1

您需要在兩者之間定義一個DataRelation

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