troubleshooting Question

How to update multiple tables in the same Dataset ??

Avatar of SteveB2175
SteveB2175 asked on
Visual Basic.NET
7 Comments2 Solutions404 ViewsLast Modified:
I have a form with 2 DataGridViews.  The first DataGridView shows user names, the 2nd dgv shows security permissions for the name that was selected in the first dgv.  All the data is from a single SQL Server table.

I bound each dgv to a dataset via code (no drag & drop). I created a single dataset, with 2 tables (maybe this was not wise ?).

My problem is that I can't find a way to update the SQL server table with a single button.  I have created 2 "update" buttons with the following code:

 Private Sub btnUpdateUserInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateUserInfo.Click
        If DS.HasChanges Then
            Dim UpdateCount As Integer = da.Update(DS.Tables("UserInfo"))
            MessageBox.Show(UpdateCount & " Records Updated")
        Else
            MessageBox.Show("Nothing to Update")
        End If
    End Sub

    Private Sub btnUpdateUsers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateUsers.Click
        If DS.HasChanges Then
            Dim UpdateCount As Integer = da.Update(DS.Tables("UserName"))
            MessageBox.Show(UpdateCount & " Records Updated")
        Else
            MessageBox.Show("Nothing to Update")
        End If
    End Sub

There are several problems here:

1) I would prefer that the user only have to click a single button to make any updates necessary.
2) If the user clicks the wrong button (trying to update the wrong DS table) an error is returned
3) I am only aware of the test "if ds.haschanges..." which tells me that there are changes, but not which table the changes exist in.

So, are there answers to my questions, should I create a separate dataset for each dgv, or am I approaching this whole thing the wrong way ??

Thanks !!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros