This is a migrated thread and some comments may be shown as answers.

Problems adding more than 1 record

0 Answers 59 Views
DomainDataSource
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 16 Sep 2013, 01:41 PM
Hi

Can anyone help with an odd issue when adding more than one record. I have the following loop setup in the loaded event of the domain datasource.

    Private Sub seasonsExcludedDateDataSource_LoadedData(sender As Object, e As DomainServices.LoadedDataEventArgs)
        If seasonid = -1 And mode = "Complete" Then
            Dim idx As Integer = e.Entities.Count + 1

            For Each seldate In rlDates.Items
                Dim seasonexcldate = New SeasonExcludedDate

                seasonexcldate.ExcludedDate = seldate
                seasonexcldate.ID = idx
                seasonexcldate.SeasonID = season.SeasonID

                seasonsExcludedDateDataSource.DataView.AddNewItem(seasonexcldate)
                idx += 1
            Next
            seasonsExcludedDateDataSource.SubmitChanges()
            mode = "Close"
        End If
    End Sub

rldates is a standard listbox and each item added is a date entry. When there is only one date in the list box the records get added fine. However when there is more than one item in the list box it falls over with no error. I can see in the event SubmittingChanges that there are 2 new records to be added however the SubmittedChanges event is never reached. No errors are thrown and the program carries on.

Can anyone throw any light on this as I am most confused?

Many Thanks

David

Solved : Needed to add CommitNew on each loop before then calling submitchanges.

Updated

        If e.HasError Then
            e.MarkErrorAsHandled()
        ElseIf seasonid = -1 Then
            Dim idx As Integer = e.Entities.Count + 1

            For Each seldate In rlDates.Items
                Dim seasonexcldate = New SeasonExcludedDate

                seasonexcldate.ExcludedDate = seldate
                seasonexcldate.ID = idx
                seasonexcldate.SeasonID = season.SeasonID

                seasonsExcludedDateDataSource.DataView.AddNewItem(seasonexcldate)
                idx += 1
                seasonsExcludedDateDataSource.DataView.CommitNew()
            Next
            seasonsExcludedDateDataSource.SubmitChanges()
        End If

No answers yet. Maybe you can help?

Tags
DomainDataSource
Asked by
David
Top achievements
Rank 1
Share this question
or