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 !!
ASKER CERTIFIED SOLUTION
Wayne Taylor (webtubbs)

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 7 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 7 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004