I have a DataGrid bind to a DataSet. On change or adding rows I'm trying to save the changes. I add the delegate for a RowChange event of the dataset which is calling itself after dataAdapter.Update(row) many times!!
NewGeoDataSet.RegionGeoDataTable reg = new NewGeoDataSet.RegionGeoDataTable();
regAdapter = new NewGeoDataSetTableAdapters.RegionGeoTableAdapter();
reg = regAdapter.GetData();
datagrid.DataContext = reg;
datagrid.ItemsSource = reg;
reg.RowChanged += new DataRowChangeEventHandler(dataset_RowChanged);
Delegate
private void dataset_RowChanged(object sender, DataRowChangeEventArgs e)
{
Console.WriteLine("row changed "+e.Action);
DataRow r = e.Row;
regAdapter.Update(r);
Console.WriteLine("data updated");
}
And eventually I'm getting:
row changed Change
row changed Change
Exception like: there is already an open datareader associated with this command
row changed Change
Exception again
row changed Commit
data updated
data updated
So the question is: why dataAdapter.Update(row) firing itself. How can I overcome it? I've tried to use bool variable to prevent further executions, but it's not reliable and dirty.
I've checked http://www.codeproject.com/Articles/30905/WPF-DataGrid-Practical-Examples it seems the same but doesn't work...
What possibly am I doing wrong?