Skip to main content

Microsoft Silverlight

Problem inserting via ADO web servicesRSS Feed

(0)

cce1911
cce1911

Member

Member

8 points

17 Posts

Problem inserting via ADO web services

I have a SQL Server db with 2 tables.

Clubs

club_id(PK)

club_name

Clubnotes

club_note_id(PK)

club_id

note

There is a FK relationship between them on club_id in the database.

I've built the web service and used datasvcutil to generate the class for my SL app. I can add, update and delete on Clubs just fine and I can read the Clubnotes and populate a second datagrid, but I'm having trouble creating a new Clubnote. Here is what I'm doing:

 

Private Sub btnAddNote_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnAddNote.Click
        Try
            Dim objClubNotes = New ClubMgrSL.clubsModel.clubnotes
            ' get the selected club object
            Dim objclub = CType(grdClubs.SelectedItem, ClubMgrSL.clubsModel.clubs) ' selected Club in the datagrid

            With objClubNotes
                .clubs = objclub
                .notes = tbxAddNotes.Text
            End With

            ' call the AddToclubnotes method
            objClubService.AddToclubnotes(objClubNotes)

            ' begin the async insert
            objClubService.BeginSaveChanges(AddressOf OnNewClubNoteComplete, objClubNotes)

        Catch ex As Exception
            DisplayTxtMessage(ex.InnerException.ToString, False, True)
        End Try
    End Sub
  
    Private Sub OnNewClubNoteComplete(ByVal result As IAsyncResult)
        Try
            ' terminate the asyc call
            objClubService.EndSaveChanges(result)
            ' get the new club
            Dim newNote = CType(result.AsyncState, ClubMgrSL.clubsModel.clubnotes)

            ' add it to the obvervable collection
            obsvCollNotes = New ObservableCollection(Of clubnotes)
            obsvCollNotes.Add(newNote)
        Catch ex As Exception
            DisplayTxtMessage("New insert error" & ex.InnerException.ToString, False, True)
        End Try
    End Sub

 My problem is that I get a vague exception at objClubService.EndSaveChanges(result)

What am I missing here? Obviously, I'm trying to insert a record in the Clubnotes table, but I'm not clear how the relationship works. Should I be using BeginSaveChanges in the button click event or something eles?

 

cce1911
cce1911

Member

Member

8 points

17 Posts

Re: Problem inserting via ADO web services

Can anyone point me to some further reading on this subject?

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities