Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Problem creating master/detail form w/customer/orders
 

Problem creating master/detail form w/customer/orders

It's a pretty simple question:

I have a few tables: customers, orders, orderdetails, products etc.

I have created relations between these tables.

The problem is that i want to create a form with ORDERS as the "master". When showing an order, i want to see details about the customer who ordered it, and details about the products that was ordered.

How would i do this?

Note: I do NOT want to have customers as master, and display orders based on which customer selected - i want the opposite, and that's the problem...

James_Steven  Tuesday, August 22, 2006 11:24 PM
Really no one who can help me with this? :(
James_Steven  Thursday, August 24, 2006 8:08 PM

Jim,

Don't let it get you down, I know everyone here is busy helping other people... I myself have had the same problem of no-replies.

I'd like to know a few things before I try to help you out...

What does your code look like where you create the relations?

Also, I think in order for this to work, you would have to have something in the order table that could point back to the customer.

For instance:

table: customer

integer primary key cust_id;

string cust_name;

integer cust_order_id;

===

table: order

integer prmary key order_id;

string order_description;

integer order_cust_id;

--

Each customer will have the cust_order_id key related to the order_id number in the order table.

Each order will have a order_cust_id key related to the cust_id number in the customer table.

Then you create your relation thusly:

mydataset.relations.add("customersorders", mydataset.Tables["customer"].Columns["cust_id"], mydataset.Tables["order"].Columns["order_cust_id"]);

mydataset.relations.add("orderscustomers", mydataset.Tables["orders"].Columns["order_id"], mydataset.Tables["customer"].Columns["cust_order_id"]);

Then you can make the relation work both ways.

I'm pretty sure my code is right, I'll double check tonight or tomorrow and let you know if this actually works.  I think this is the right idea though... NOTE that you can only have one customer for each order, and only one order for each customer the way that these tables are set up.

The point I'm trying to get across is, you have to have a key in your master table that relates to your child table in order to make the relation work correctly.  If you had no key in the order table that pointed to the customer key, you wouldn't be able to build a working relation.

Sincerely,

Gordon E.

grellsworth  Thursday, August 24, 2006 9:03 PM

Hi,

Thanks for the reply!

Unfortunately, a customer must be able to place more than one order... So i believe there's no way i can achieve this without writing the code manually?

James_Steven  Friday, August 25, 2006 12:16 AM

The solution could be to create a Table of Customers with a primary Key and a relation one to many to the table of order.

Selection of the Client record, will give you access to the child with all the orders related to that Client.

Other solution is to make a filter with the Customer ID in the order table.

Bruno VB Express Discover  Friday, August 25, 2006 7:25 AM

Sorry for not reading the things properly. Whay you need is the opposite. But, in fact, this is symetrical just replace Order by Client in the above.

In fact, make a Client Table, an Order Table with relation one to many toan Order Details Table.

Selecting one relation or the other, you will either get Childrecords in the Order Table for Client or Order.

This can even be made graphically!

Or again, use filter.

Bruno VB Express Discover  Friday, August 25, 2006 7:31 AM

You can use google to search for other answers

Custom Search

More Threads

• Tracking DataGridViewComboBoxColumn doublick event
• cannot get the correct value after change the selected row
• show Details in Master-Detail DataGrid
• Unable to Edit Relation in DataSet Designer in VS2008
• Databinding to a DateTimePicker control
• Displaying the next item in a data table
• Two-way databinding
• Create Editable DataGrid Vb.Net Windows Forms
• Custom EditingControls, Cells & Columns
• DataGridView with objects