none
DataSet.AcceptChanges

    Question

  • If i have a dataset binded to a datagird and i make some changes on those columns on that datagrid and when i click a buttons my dataset calles its AcceptChanges method will that update those changes in my dataset so that when i open my form again those changes are still there within that column of the row that i changed in my datagrid???
    Monday, November 20, 2006 5:55 PM

Answers

  • Hi,

    AcceptChanges only updates your rows in the (in memory) dataset, that is - marks them as "not needed for actual database update". If you want to update your rows to the database, call your tableadapter's Update method. This method will call AcceptChanges on your rows if the rows get successfully updated to the database. The point here is, you should only call AcceptChanges on your rows, if you don't want them to be sent to your database to update records.

    I hope I understood your question...

    Andrej

    Monday, November 20, 2006 7:39 PM
  • Andrej said it very correctly. Alot of people use AcceptChanges and wonder why their database was not updated. you should not call accept changes (lock your hands to your seat and don't touch that keyboard!!) :-) when changing values from a bound control, the datasource will be updated automatically. Next thing needs to be done is to call the Update() command of the dataAdapter/TableAdapter so it can then go through the rows that are needed to be updated to the database and it will execute the appropriate commands to do so. It will then call accept changes automatically I believe on the dataset after doing this.
    Monday, November 20, 2006 7:47 PM
  • One thing that I have noticed about this however. When I make changes to several different rows in dataSet I will get all my changes accept for the very last one when I call DataAdapter.Update ( dataSet );

     

    To get around this I called endEdit on the rows in the table that I am changing and that ensures that all records that were edited get propagated to the database.

    Wednesday, June 27, 2007 10:44 PM

All replies

  • Hi,

    AcceptChanges only updates your rows in the (in memory) dataset, that is - marks them as "not needed for actual database update". If you want to update your rows to the database, call your tableadapter's Update method. This method will call AcceptChanges on your rows if the rows get successfully updated to the database. The point here is, you should only call AcceptChanges on your rows, if you don't want them to be sent to your database to update records.

    I hope I understood your question...

    Andrej

    Monday, November 20, 2006 7:39 PM
  • Andrej said it very correctly. Alot of people use AcceptChanges and wonder why their database was not updated. you should not call accept changes (lock your hands to your seat and don't touch that keyboard!!) :-) when changing values from a bound control, the datasource will be updated automatically. Next thing needs to be done is to call the Update() command of the dataAdapter/TableAdapter so it can then go through the rows that are needed to be updated to the database and it will execute the appropriate commands to do so. It will then call accept changes automatically I believe on the dataset after doing this.
    Monday, November 20, 2006 7:47 PM
  • One thing that I have noticed about this however. When I make changes to several different rows in dataSet I will get all my changes accept for the very last one when I call DataAdapter.Update ( dataSet );

     

    To get around this I called endEdit on the rows in the table that I am changing and that ensures that all records that were edited get propagated to the database.

    Wednesday, June 27, 2007 10:44 PM
  • Which object is my DataAdaptor?

     

    I cannot find the Update methode anywhere.

     

    I have a SQL Server Table that I connect to with a DataSet Object, and then I use a BindingSource with the DataSet.

     

    I then call the AddTableRow Method, and AcceptChanges (which I now know will not work).

     

    Which object is the DataAdaptor that contains the Update method?

     

    Thanks

    -Alex

    Monday, August 27, 2007 1:50 AM
  • It is a SqlDataAdapter or OleDbDataAdapter depending on which data object you are using. Within that object, will be the Update method.

     

    What exactly is your question or doubts you have? Perhaps if you can explain more we can help better.

     

    Monday, August 27, 2007 1:58 AM
  •  

    Thank you for you timely reply.

     

    I'm just trying to add data to a table I created with the Database Designer in Visual C# studio.

     

    I created a table named DataTable1 within the database dbTutorial.  I created a DataSet and a BindingSource using the visual components, and then wrote this code to add an entry:

     

    dbTutorialDataSet1.DataTable1.AddDataTable1Row("first", "Shoes", 20);

    dbTutorialDataSet1.DataTable1.AcceptChanges();

     

    This does not work, as you have mentioned, I need to use Update() to comit the DB changes.  I dont know which object to call the Update method on.

     

    -Alex

    Monday, August 27, 2007 4:18 AM
  • ok I see. The designer mode is slightly different. You need to find the TableAdapter instead, which will contain an Update method I think (Its been a while for me, I maybe wrong)

    Do you have a TableAdapter available? (perhaps something like dbTutorialTableAdapter?)

     

    Monday, August 27, 2007 1:39 PM
  • No.... I cant find anything like that.

     

    the only object I have are:

     

    dataTable1BindingSource

    DataTable

    DBTutorialDataSet

    dbTutorialDataSet1

     

    and none of them or any of their component objects contain the update() method.  Well, some of them have an update() method, but its for redrawing visual componenets, not comitting changes to the database.

     

    I think I've had it with these visual components.  I'm just going to use the SqlDataAdapter object and go from there.

     

    Thanks for all your help

     

    -Alex

    Tuesday, August 28, 2007 3:28 AM