Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retaining Child Records in Dataset Prior to Parent Creation...

Status
Not open for further replies.

MrTrue

Technical User
Jul 28, 2008
46
US
Ok, It's been a while since I posted last and I'm really hoping to get some general feedback/ideas here... My issue is this. I have a databound winform which updates a parent table. (Simple enough with a bindingsource) On that form I have a datagridview which is not bound to the parent table. This datagridview has checkboxes and based on the the items the user checks, a variable number of records get inserted into a child table (joined by the parent tables identity value).

What I want to do, is make this as seamless as possible. (ie. User clicks submit, the bound controls are updated creating a new record and the child rows are inserted....

Whats the best way to do this? I am guessing I can't use the child tables bindingsource (tied to the relationsship) since I don't have the ID propogated for the parent table yet?

In addition, the datagridview data does not relate directly to the child table that gets updated other than a unique ID that each row contains. (It basicaly displays domain values and ID's which I will be inserting into some history tables)

Should I create a temporary table that contains my rows for my child table (minus the ID column) then add the ID on submit and pass that whole temp table to the child table at that point? If anyone has a good simple example, I'd really appreciate the feedback. My code is currently very minimal as I've used primarily the bindingsource/table adapter to handle most everything.
 
Ok, I think I resolved this. If anyone has a better solution. Please feel free to let me know, otherwise, this is how I handled.

Code:
        'parent table editing is ended generating an identity value
        Me.EMP_RVWBindingSource.EndEdit()
        Me.EMP_RVWTableAdapter.Update(ClaimsQualityReviewsDataSet.EMP_RVW)

        ' Update the child binding source by looping through my temp table after main record is created.
        For Each r As DataRow In CurrentError.CurrentErrorTable.Rows
            Me.R2BindingSource.AddNew()
            Me.R2BindingSource.Current("ERR_FDBK_TXT") = r.Item("ERR_FDBK_TXT")
            Me.R2BindingSource.Current("FDBK_ONLY_FLG") = r.Item("FDBK_ONLY_FLG")
            Me.R2BindingSource.Current("RVW_CTGRY_QSTN_ID") = r.Item("RVW_CTGRY_QSTN_ID")
        Next
        'end editing of child relationship table and commit changes via table adapter
        Me.R2BindingSource.EndEdit()
        Me.EMP_ERRTableAdapter.Update(Me.ClaimsQualityReviewsDataSet.EMP_ERR)
        Me.TableAdapterManager.UpdateAll(Me.ClaimsQualityReviewsDataSet)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top