2012-11-09 41 views
0
DataSet customerOrders = new DataSet(); 
DataSet.CustomersDataTable customers = new DataSet.CustomersDataTable(); 
CustomersTableAdapter adapter = new CustomersTableAdapter(); 
adapter.Fill(customers); 

DataSet.OrdersDataTable orders = new DataSet.OrdersDataTable(); 
OrdersTableAdapter oAdapter = new OrdersTableAdapter(); 
oAdapter.Fill(orders); 

DataRelation relation = (DataRelation)customerOrders.Relations[0]; 


foreach (DataRow row in customers.Rows) 
{ 
    foreach (DataRow orderRow in row.GetChildRows(relation)) 
    { 
     Response.Write(orderRow["OrderID"].ToString()); 
    } 
} 

我得到此異常:該行不屬於與此關係相同的DataSet。該行不屬於與此關係相同的數據集

我在做什麼錯?

+0

我有一個疑問,改變的代碼

DataSet.CustomersDataTable customers = new DataSet.CustomersDataTable(); 

這個片段。 'foreach(DataRow orderRow in row.GetChildRows(relation))'的目的是什麼? –

回答

0

客戶DataTable不屬於customerOrdersDataSet

您必須通過此

DataSet.CustomersDataTable customers = customerOrders.Tables.Add("Customers"); 
+0

夠公平的.....很好 –

相關問題