Saving DataSet changes on a DataGrid

Posted on 2006-04-05
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

            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
Question by:seinc
    LVL 48

    Expert Comment

    when you stepthrough the code what happens?

    Author Comment

    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.
    LVL 18

    Accepted Solution

    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


    Author Comment

    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now