By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

Master detail design

P: n/a
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
Jun 24 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"John" wrote:
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
Jun 24 '07 #2

P: n/a
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_Cus tomers"]);

Hope this helps...
-Mike
"John" wrote:
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
Jun 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.