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

x
  • 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
        Try

            myDataSet.Tables("g_sra").Rows(dgSRA.CurrentRowIndex).EndEdit()
            MyDataAdaptr1.Update(myDataSet, "g_sra")

            myDataSet("g_sra_assc").Rows(dgSRA.CurrentRowIndex).EndEdit()
            myDataAdaptr2.Update(myDataSet, "g_sra_assc")

            myFrmMsg = New frmMsg("Save Successful!")
            myFrmMsg.Show()

        Catch sce As SqlClient.SqlException
            MsgBox("Please fix errors.")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
0
seinc
Asked:
seinc
  • 2
1 Solution
 
Mikal613Commented:
when you stepthrough the code what happens?
0
 
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.
0
 
UnifiedISCommented:
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

0
 
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.
0

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