We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Saving DataSet changes on a DataGrid

seinc
seinc asked
on
Medium Priority
237 Views
Last Modified: 2010-04-23
  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
Comment
Watch Question

CERTIFIED EXPERT

Commented:
when you stepthrough the code what happens?

Author

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.