Advice on determining which table to update using Dataset.HasChanges property

I have a .Net 2.0 WinForms application which displays and allows users to edit data concerning corporate contacts. It has one dataset with many tables. Users can select a contact and make changes to the tables' data, then when they move to another record or close the form, my code examines the dataset.haschanges property. If it's true, I need to see which table has been changed in order to determine which update stored proc to run. My code for how to do this is attached, and my question is does this look OK to you, does it look like the right way to do it? And if not can anyone suggest an alternative (I know it may be that there's a whole other approach which I'm not aware of).

Private Sub GetTableName()
            'variables for table names
            Dim sContactsTable As String = "SpContacts1"
            Dim sOrgTable As String = "spOrgs1"
            Dim sOwnerTable As String = "spContactOwner"
            Dim sRelationshipsTable As String = "spContactcorporatePeople"
            'dataset, tables and rows
            dsChanges = frmData.Ds1.GetChanges(DataRowState.Modified Or DataRowState.Deleted)
            Dim modItems As New ArrayList
            Dim sMod As String = ""
            Dim delItems As New ArrayList
            Dim sDel As String = ""
            For Each t In dsChanges.Tables
                For Each r In t.Rows
                    If r.RowState = DataRowState.Modified Then modItems.Add(t.TableName)
                Next r
            Next t
            For i As Integer = 0 To modItems.Count - 1
                sMod += modItems.Item(i) & " "
            '2. run stored procedures
            If sMod.Contains(sContactsTable) Then
                sConfirm = "Please confirm changes to " & cRow("Contact")
                If MessageBox.Show(sConfirm, "Please confirm your changes", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
                Else : frmData.Ds1.RejectChanges()
                End If
            End If
            If sMod.Contains(sOrgTable) Then
                sConfirm = "Please confirm changes to " & _
                oRow("OrganisationName", DataRowVersion.Original) & vbCrLf & _
                "This change will affect all contacts at " _
                & oRow("OrganisationName", DataRowVersion.Original) & _
                ". Please confirm that you wish to continue."
                If MessageBox.Show(sConfirm, "Please confirm change", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
                Else : frmData.Ds1.RejectChanges()
                End If
            End If
            If sMod.Contains(sRelationshipsTable) Then
                sConfirm = "Please confirm changes to corporate relationships for " & cRow("Contact")
                If MessageBox.Show(sConfirm, "Please confirm", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then UpdatecorporatePeople()
            End If
        Catch ex As Exception
            LogException("Exception", ex.ToString, "frmContacts GetTableName")
            MessageBox.Show(sExText, sExCaption, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


 this will give u all changes only changed rows,,, if u iterate through dschanges and find tables whose row count is greater then 0 then ur problem will be solved insa.

   dsChanges = frmData.Ds1.GetChanges()

   For Each t In dsChanges.Tables
                For Each r In t.Rows.COUNT > 0
                Next r
            Next t

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Your code looks fine... it's elegant and efficient
louise001Author Commented:
Thanks very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.