G
Guest
Hi,
I'm just learning how to create a 1 to M with ADO.NET.
I've created this little test app. A user selects a company name from the
list, then clicks a button containing the code below. The code is meant to
return all the child rows of the related parent row that has been clicked and
display them in a grid. Unfortunately it seems to be returning the entire
child table, not simply the related rows. What could I be doing wrong here?
(I'm using VS2003)
Thanks for any suggestions in advance
Ant
// First create a dataset
DataSet dsCustomers = new DataSet();
// Add tables to it
dsCustomers.Tables.Add("Customers");
dsCustomers.Tables.Add("Orders");
// Fill it & give it schema
daCustomers.Fill(dsCustomers.Tables["Customers"]);
daOrders.Fill(dsCustomers.Tables["Orders"]);
// Add a relation to it
dsCustomers.Relations.Add("Child",
dsCustomers.Tables["Customers"].Columns["CustomerID"],
dsCustomers.Tables["Orders"].Columns["CustomerID"]
);
// Get a view of the selected row
DataRowView selectedRow = (DataRowView)lstParent.SelectedItem;
// Retrieve child rows into ds using Child relation
dsCustomers.Merge(selectedRow.Row.GetChildRows("Child"));
// Bind child table to grid
dgChild.SetDataBinding(dsCustomers,"Orders");
dgChild.Refresh();
Thank you.
I'm just learning how to create a 1 to M with ADO.NET.
I've created this little test app. A user selects a company name from the
list, then clicks a button containing the code below. The code is meant to
return all the child rows of the related parent row that has been clicked and
display them in a grid. Unfortunately it seems to be returning the entire
child table, not simply the related rows. What could I be doing wrong here?
(I'm using VS2003)
Thanks for any suggestions in advance
Ant
// First create a dataset
DataSet dsCustomers = new DataSet();
// Add tables to it
dsCustomers.Tables.Add("Customers");
dsCustomers.Tables.Add("Orders");
// Fill it & give it schema
daCustomers.Fill(dsCustomers.Tables["Customers"]);
daOrders.Fill(dsCustomers.Tables["Orders"]);
// Add a relation to it
dsCustomers.Relations.Add("Child",
dsCustomers.Tables["Customers"].Columns["CustomerID"],
dsCustomers.Tables["Orders"].Columns["CustomerID"]
);
// Get a view of the selected row
DataRowView selectedRow = (DataRowView)lstParent.SelectedItem;
// Retrieve child rows into ds using Child relation
dsCustomers.Merge(selectedRow.Row.GetChildRows("Child"));
// Bind child table to grid
dgChild.SetDataBinding(dsCustomers,"Orders");
dgChild.Refresh();
Thank you.