Master detail design

J

John

Hi

I am trying to create a master/detail form. I have my master and details
tables dragged onto the dataset. I have also dragged the fields from master
table on the form which has created the navigation toolbar for me and which
works fine with the master table. I also have a dataview on the same form
ready for detail table but as yet not assigned to the detail table. How can
I now create a master/detail relationship between my master and detail
tables such that the detail table shows up in the dataview control.?

Thanks

Regards
 
G

Guest

John,

You would need to create a dataset relationship between your master and
details tables. For example, a Customers/Orders relationship is created as
follows:

DataRelation dr = new DataRelation("CustomerOrder",
ds.Tables["Customers"].Columns["CustID"],
ds.Tables["Orders"].Columns["CustID"]);
ds.Relations.Add(dr);

Next, for the customer/order example shown above, you would set up your
grids as follows:

productsGrid.DataSource = ds;
productsGrid.DataMember = ds["Customers"]

ordersGrid.DataSource = ds;
ordersGrid.DataMember = "Customers.CustomerOrder";

By the way, if you have a master row, and you want to programatically get
the children, do the following:

DataRow [] rowsOrder = rowCustomer.GetChildRows(ds.Relations["CustomerOrder"])

-Mike
 
G

Guest

John,

You would need to set up a relationship in your dataset for the mater/detail
tables. For example, a Customer/Order master detail would be done as follows:

DataRelation dr = new DataRelation("CustomerOrder",
ds.Tables["Customers"].Columns["CustID"],
ds.Tables["Orders"].Columns["CustID"]);
ds.Relations.Add(dr);

Then set up your grids as follows:

customersDataGridView.DataSource = ds;
customersDataGridView.DataMember = "Customers";

ordersDataGridView.DataSource = ds;
ordersDataGridView.DataMember = "Customers.FK_Orders_Customers"

If you want to programatically access summary row's detail records, do the
following:

DataRow[] detOrders =
rowCustomer.GetParentRows("Customers.FK_Orders_Customers"]);

Hope this helps...
-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top