|
-
Mar 10th, 2015, 06:34 PM
#1
Thread Starter
Lively Member
How to save new Auto Increment Id in Parent Child tables - eg Orders and Orderlines
Greetings
I am trying to create a quoting database, using Visual Studio 2012, vb.net and sql express tables.
It is the same as the OrderHeader Orderline concept where the user will enter a new order and orderlines, and then save or cancel.
If the user saves the quote I want to update a Quoteheader table with Header details including an ID, and a Quotelines table with the QuoteHeader Id and line details.
At the moment I am opening a Dataset, and connecting a QuoteHeaderTableAdapter, and QuotelinesTableAdapter. I am able to click on an existing QuoteHeader and show the relevant QuoteLines in a bound dataviewgrid. I can then click on a Quoteline and show a new form with relevant QuoteLine details.
My problem is how to save the related data when creating New Quotes or Quotelines.
Currently the user may create a new quote - and when they click save I set a QuoteId and loop through the Quotelines datatable to assign that Id to each line
For Each dr As DataRow In dTable.Rows
dr.Item("QuoteId") = scrQuoteId.Text ' Populate
Next
Me.QuoteHeaderBindingSource.EndEdit() ' Keep Changes
Me.QuoteLinesBindingSource.EndEdit() ' Keep Changes
QuoteHeaderTableAdapter.Update(DataSet1.QuoteHeader)
QuoteLinesTableAdapter.Update(DataSet1.QuoteLines)
I realise that I should be able to Auto Increment the QuoteId by defining it in the database as ID INT IDENTITY PRIMARY KEY
But then how does this get saved on the Quotelines table?
Googling has lead me to topics such as Parent Child Relationships and TableAdapterManager.UpdateAll but I do not understand how to use them. And I would like to understand the best (and easiest) way to do this type of thing for the next part of my project, ... entering the QuoteLine detail as a third level.
A quoteline can be one of 5 types, that require different data. I have created a table and a windows form for each type. Each table will have a QuoteId and I am thinking that each table should have an Auto Increment Id
I want the user to be able to enter these different types of Quotelines (on different forms) and click save, which will add a new quoteline to the bound QuoteLinedatagridview. When they have finished entering lines they can click Save or Cancel. Only save will update the datatables.
So - to summarise - The various QuoteLineType tables will have a QuoteId and a AutoIncrement ID
The QuoteLine Table will have a QuoteId and a QuoteLineTypeId
The QuoteHeaderTable will have a QuoteId
But none of the New Auto Increment Ids are created until the data is saved, so how do they get placed in the related tables?
(Note: Sometimes entry of a Quotetype can add two lines to the orderlines table - so two lines can link to one Quotetype)
Thanks for reading - I hope I was clear.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|