Problems adding more than 1 record

1 posts, 0 answers
  1. David
    David avatar
    1 posts
    Member since:
    Aug 2013

    Posted 16 Sep 2013 Link to this post

    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
Back to Top