G
Guest
Hi,
I want to display an n:m relation in Windows without showing the in-between
table.
As an example, I used the Orders, Order Details and Products tables from the
Northwind database.
I use a ComboBox for the parent and want the details in a DataGrid
I have set up a form and added some SqlDataAdapters and a DataSet, ComboBox
and DataGrid.
(using Visual Studio 2003).
Here is the code I added:
System.Data.DataColumn masterCol;
System.Data.DataColumn detailCol;
DataRelation dr;
// Let the DataAdapters fill the DataSet
DA_Orders.Fill(dataSet11);
DA_Products.Fill(dataSet11);
DA_OrderDetails.Fill(dataSet11);
//add relation Orders - Order Details
masterCol = dataSet11.Tables["Orders"].Columns["OrderID"];
detailCol = dataSet11.Tables["Order Details"].Columns["OrderID"];
dr = new DataRelation("OrdersToOrderDetails",masterCol,detailCol);
dataSet11.Relations.Add(dr);
//add relation Order Details - Products
masterCol = dataSet11.Tables["Order Details"].Columns["ProductID"];
detailCol = dataSet11.Tables["Products"].Columns["ProductID"];
dr = new DataRelation("OrderDetailsToProducts",masterCol,detailCol,false);
dataSet11.Relations.Add(dr);
// Let the ComboBox display the OrderID
comboBox1.DataSource = dataSet11;
comboBox1.DisplayMember = "Orders.OrderID";
// Let the DataGrid display the OrderDetails
dataGrid1.DataSource = dataSet11;
dataGrid1.DataMember = "Orders.OrdersToOrderDetails";
When the DataGrid has "AllowNavigation" set to true, everything works fine.
I get 3 Order details records, and by pressing "+" I can go to the Products
information.
!!!! However, I don't want to see the in-between table Order Details !!!!!
So I tried setting
dataGrid1.DataMember = "Orders.OrdersToOrderDetails.OrderDetailsToProducts",
in an attempt to leave out the in-between table, and directly show the
Products.
But now I don't see 3 Products anymore, I only see the first one.
What is the best way to hide the Order Details?
Thanks in advance,
Alexander van Buitenen.
I want to display an n:m relation in Windows without showing the in-between
table.
As an example, I used the Orders, Order Details and Products tables from the
Northwind database.
I use a ComboBox for the parent and want the details in a DataGrid
I have set up a form and added some SqlDataAdapters and a DataSet, ComboBox
and DataGrid.
(using Visual Studio 2003).
Here is the code I added:
System.Data.DataColumn masterCol;
System.Data.DataColumn detailCol;
DataRelation dr;
// Let the DataAdapters fill the DataSet
DA_Orders.Fill(dataSet11);
DA_Products.Fill(dataSet11);
DA_OrderDetails.Fill(dataSet11);
//add relation Orders - Order Details
masterCol = dataSet11.Tables["Orders"].Columns["OrderID"];
detailCol = dataSet11.Tables["Order Details"].Columns["OrderID"];
dr = new DataRelation("OrdersToOrderDetails",masterCol,detailCol);
dataSet11.Relations.Add(dr);
//add relation Order Details - Products
masterCol = dataSet11.Tables["Order Details"].Columns["ProductID"];
detailCol = dataSet11.Tables["Products"].Columns["ProductID"];
dr = new DataRelation("OrderDetailsToProducts",masterCol,detailCol,false);
dataSet11.Relations.Add(dr);
// Let the ComboBox display the OrderID
comboBox1.DataSource = dataSet11;
comboBox1.DisplayMember = "Orders.OrderID";
// Let the DataGrid display the OrderDetails
dataGrid1.DataSource = dataSet11;
dataGrid1.DataMember = "Orders.OrdersToOrderDetails";
When the DataGrid has "AllowNavigation" set to true, everything works fine.
I get 3 Order details records, and by pressing "+" I can go to the Products
information.
!!!! However, I don't want to see the in-between table Order Details !!!!!
So I tried setting
dataGrid1.DataMember = "Orders.OrdersToOrderDetails.OrderDetailsToProducts",
in an attempt to leave out the in-between table, and directly show the
Products.
But now I don't see 3 Products anymore, I only see the first one.
What is the best way to hide the Order Details?
Thanks in advance,
Alexander van Buitenen.