Data Adapter Updates not happening

I have an Infragistics grid bound to a BindingSource, that in turn is bound to a strongly typed dataset.  I want to add a row to the grid, then when the user click the OK button, save the new row back to the SQL Express database I am using.

In the OK button, I have this code:



this.productFeatureBrowserDataSet.Versions.AcceptChanges();
this.versionsTableAdapter.Update(
    this.productFeatureBrowserDataSet.Versions
);

 


When I click the button, the code runs, but the new grid row never gets added to the Database table.  If I break on the Update command, I can see that the Versions table does in fact contain the new row, but its just not getting saved to the database, and I do not know how to set up a SQL Profile to see if the SQL is actually firing on the SQL server to save the record.

Help is appreciated

Devin


Answer this question

Data Adapter Updates not happening

  • Berni Ployer

    Look like your "productFeatureBrowserDataSet.Versions" is a DataSet object, and "versionsTableAdapter" an DataAdapter object.

    To update the data source with any changes made to a DataSet, you can call
     
    DataSetObj.GetChanges();   

    or forget this, the DataAdapter object would find the changes anyway. However, you should not call

    DataSetObj.AcceptChanges();

    before calling

    dataAdapterObj.Update(DataSetObj)

    AcceptChanges() would remove the updated, new, deleted rows in its tables, so Update() would not find any changed rows left to update.

  • AttilaSz


    Omit the call to AcceptChanges.

    DataAdapters (and TableAdapters) implicitly call AcceptChanges after they've successfully submitted the pending changes in a DataRow.  Calling AcceptChanges on a DataRow tells the DataRow that it no longer needs to maintain the changes it has stored and marks the row as Unchanged.

    Because you've called AcceptChanges prior to calling Update, there are no changes to submit.

    I hope this information proves helpful.


  • Snyder_PlayMaker

    David Sceppa - Microsoft wrote:

    Omit the call to AcceptChanges.

    DataAdapters (and TableAdapters) implicitly call AcceptChanges after they've successfully submitted the pending changes in a DataRow. Calling AcceptChanges on a DataRow tells the DataRow that it no longer needs to maintain the changes it has stored and marks the row as Unchanged.

    Because you've called AcceptChanges prior to calling Update, there are no changes to submit.

    I hope this information proves helpful.

    Hi again David!

    This thread is already dated but I rather add my post here rather than creating new on since my question has something to do with the AcceptChanges().

    I just wonder, what are the circumstances wherein explicit call to AcceptChanges() is actually useful


  • cwes99_03

    When the DataAdapter RowUpdating event is fired, you have an opportunity to override the registered action commands (UpdateCommand, DeleteCommand, InsertCommand) and perform your own operation(s) or do nothing. In any case, to tell ADO.NET that you have sucessfully completed the operation (one way or another) you must call the AcceptChanges method. This resets the State property on the rows and ADO.NET is happy (as a data access interface can be given the circumstances of its existence).

    AcceptChanges should never be called in the ordinary course of executing the Update method. It discards the state data needed to know which rows have changed.

    ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref4/html/E_System_Data_SqlClient_SqlDataAdapter_RowUpdating.htm

    hth



  • DiverChris

    Hi Devin.

    This question seems to be related more the ADO.Net than Windows.Forms.

    Can you post your question to the ADO.Net forum

    Thanks,
    Daniel.

  • Data Adapter Updates not happening