Reputation: 24364
Situation: WPF application, .NET4, DataSource (MS SQL Server 2008) created with the designer
Problem: Reading data works well:
adapter.Fill(ds);
DataSet
is populated with data, tables bound to DataGrids. When I then edit any DataGrid
(e.g. add one row) and press "Enter" in WPF's DataGrid
, the new row is added successfuly.
Then I call:
ds.AcceptChanges();
adapter.Update(ds);
But no change is made to the underlying MS SQL Server 2008 database. It's insane, does anybody know where the problem is?
Upvotes: 1
Views: 4266
Reputation: 270
You should call AcceptChanges
after Update
, or actually not at all.
http://msdn.microsoft.com/en-us/library/system.data.dataset.acceptchanges.aspx
AcceptChanges
marks all the rows in the dataset as unchanged, so Update
sees no changes and won't update the database.
Upvotes: 4
Reputation: 57
I found the same being true when using a form with a datagrid (on a different machine under a Server 2012 operating system with VS 2013 Express for Windows Desktop in a Windows Forms application).
I added a button, the click event of the button calls the update method:
this.customersTableAdapter.Update(this.database1DataSet);
MessageBox.Show("Save was done.");
I added the MessageBox only to see that s.th. happened, as I do not trust this IDE any longer.
The changes done in the datagrid reflect in the form. No complaint from VS or Windows. I run it again: the data was not saved to the database.
It just is a buggy thing and does not deserve all the attention it gets.
May be it is all by design.
Sooo long,
Andi
Upvotes: 0
Reputation: 111
this is still unsolved and I have the same issue.
On the tableadapter you can do an tableadaptername.Update(dataset.NameofDataset).
However, this does not write thru to the database.
The named DataSet only knows of an AcceptChanges but not of an Update after the Dot-operator.
So, this is unsolved for four years... There are other posts like this, too...
Just do not answer this if it doesn't make any difference - and AcceptChanges here is NOT relevant.
Sincerely,
Andi
Upvotes: 0
Reputation: 614
Have you specified your update and insert sql statements/stored procs in the data adapter?
One other thing to look at is the return value from the dataAdapter (int) which is the number of rows that were successfully updated. Is this coming back with a value?
Can you post your data adapter initialization code?
Upvotes: 0