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。

我究竟做错了什么?

4

1 回答 1

0

您的客户 DataTable不属于customerOrders DataSet

您必须更改此代码片段

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

这样

DataSet.CustomersDataTable customers = customerOrders.Tables.Add("Customers");
于 2012-11-09T18:04:23.553 回答