Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Saving DataSet changes on a DataGrid

  I have a button that saves changes to a DataSet. The data saves if I click the button, but if I use the alt shortcut, the changes don't make it to the database and the "HasChanges" property stays true.
The button click event fires  whether I click the button or use the alt shortcut.

 Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

            MyDataAdaptr1.Update(myDataSet, "g_sra")

            myDataAdaptr2.Update(myDataSet, "g_sra_assc")

            myFrmMsg = New frmMsg("Save Successful!")

        Catch sce As SqlClient.SqlException
            MsgBox("Please fix errors.")
        Catch ex As Exception
        End Try
    End Sub
  • 2
1 Solution
when you stepthrough the code what happens?
seincAuthor Commented:
Every line executes whether I click the button or use the alt shortcut.
If I use the alt shortcut, the little pencil icon in the datagrid row does not go away. It does go away if I click the button.
You answered your own question!  The changes have not been committed if the pencil icon is still there.
do a dataset.acceptchanges before the update

seincAuthor Commented:
I am wondering why the change does not commit when the exact same code executes whether I click the button or type alt-U. I am calling endedit in case the user does not move to a different row.
If I call AcceptChanges, no updates will make it to the database since it makes added and modified rows "Unchanged" - the dataadapter will only update modified, added, and deleted rows.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now