Avatar billede neoman Novice
17. april 2007 - 12:07 Der er 1 løsning

Tilføje childrows til child-tabel før update af parent tabellen

Jeg kan ikke få gemt mine childrows før jeg kører adapter.update på parent tabellen. Med andre ord , hvis jeg laver update på parent før jeg tilføjer mine childrows til datasættet, så gemmes mine childrows, hvis jeg først kører update på parent efter at have tilføjet childrows, så gemems der ingen childrows når jeg kører update på deres adapater. Jeg gør tydeligvis noget forkert, men hvad ?

I have the parent  table Tasks with TaskID as PK ,  the child table Slots with SlotID as PK and TaskID as FK. and an FK_Tasks_Slots relation.

    Dim ds As New RosterDataSet
        Dim adapter As New ActivitiesTableAdapter
        adapter.FillByActivity(ds.Activities, 88)
        Dim adapter2 As New TasksTableAdapter
        Dim adapter4 As New SlotsTableAdapter

        Dim Task As RosterDataSet.TasksRow
        Dim Slot As RosterDataSet.SlotsRow

        ' create new task
        Task = ds.Tasks.NewTasksRow
        Task.ActivityID = 88
        'add it to table
        ds.Tasks.AddTasksRow(Task)

        'create new slot
        Slot = ds.Slots.NewSlotsRow
        Slot.SlotStart = Now
        'set it up as child of the task
        Slot.SetParentRow(Task)

        'update tasks
        adapter2.Update(ds.Tasks) ' if I update ds.Tasks HERE then my child does NOT get stored in DB later, when I call  adapter4.update

        ds.Slots.AddSlotsRow(Slot)

        'adapter2.Update(ds.Tasks) ' if I update ds.Tasks HERE , the my child gest stored in DB later, when I call adapter4.update
        'update slots
        adapter4.Update(ds.Slots)
Avatar billede neoman Novice
17. april 2007 - 18:29 #1
Og svaret blev fundet efte 6 timers søgen på nettet :
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=189482&SiteID=1

-------
John,

It sounds like the ForeignKeyConstraint that's associated with your DataRelation has its AcceptRejectRule property set to Cascade.

The DataAdapter (and TableAdapter) implicitly calls AcceptChanges on a DataRow during Update if it determines that it successfully submitted the pending change stored in that DataRow.  This helps make sure that multiple calls to DataAdapter.Update won't try to submit the same pending changes multiple times.  As a result, the RowState of the DataRow will be set to Unchanged after submitting the pending insert.

The ForeignKeyConstraint class' AcceptRejectRule will cascade the call to AcceptChanges (or RejectChanges) if the property is set to Cascade.  It sounds like that's what's happening here.  If you set the property to None (its default), you should see the desired behavior.

I hope this information proves helpful.


David Sceppa / ADO.NET Program Manager / Microsoft
-------


Med andre ord, skal man lige passe på med AcceptRejectRule i definitionen af relationen.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester