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 !!
Our community of experts have been thoroughly vetted for their expertise and industry experience.