Create Master/Detail Form in C# with Sql Server 2005

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
This is with reference with continuation of a simple Database driven project using Visual C# 2010 and Sql Server 2005 help by Bonnie Berent DeWitt and Mitja located
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/977089d2-2230-411d-b0e8-1c509e9f1ed0" target="_blank" title="SqlDataAdapter Update is not working in C# with SQL Server 2005
here . As per suggestions I am starting new thread for extending this simple application to convert in Master/Details with foreign Key in detail table.
This project as previous uses Northwind database and previously it was only
Orders table, now the need to add Detail table for entering line items required to Add
OrderDetails table of same Northwind database. For user GUI OrderDetails will be input by DataGridView to handle entering Line items for each order. As Ive searched the net for this issue the most common problem a newbie like me faced is how
to handle foreign key in Detail table? One suggestion by Bonnie I am quoting here:
<pre class="prettyprint // Do this prior to saving OrderDetails
// The MasterOrderID is passed to the Detail form
// from the Master form
foreach (DataRow row in dtOrderDetails.Rows)
{
row["OrderID"] = MasterOrderID;
}[/code]
I am using a new Binding source for detail table also, and then assign DataGridView.Datasource to that Binding source. The suggestion by Bonnie will work when entering new data, but what will happen when after data is saved and user need to enter/edit/delete
from line items of same order? how should I handle that?<br/>

Kindly comment/suggest any code, I will be much appreciate for your help as always.
Thanks
Ahmed
<hr class="sig Ahmed Hashim

View the full article
 
Back
Top