By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

DataTable AcceptChanges set RowState to Modified

P: 2
I have a DataSet I am loading via the DataSet.Tables.Add() method. I call the AcceptChanges method on the DataTable first thing. Every thing looks good i.e. RowStates are all Unchanged. I then bind this datatable to an Infragistics Calendarinfo AppointmentsDataBinding object. Everything still going smooth. I run the app and update an appointment. As expected, it updates the datarow and the RowState is changed to Modified. Still going great. I do a DataTable GetChanges() to send my changes to a web service and update the database. Works great. But this is were the trouble starts. After the web service call comes back, I do a DataTable AcceptChanges() to my bound datatable expecting to set only my Modified RowState rows to Unchanged. But what happens is that it sets every row in the DataTable to a RowState of Modified (including rows that are Unchanged).

I only want to set the rows I manually updated from RowState Modified to Unchanged; not every row RowState from Unchanged to Modified.

Any suggestions?

I did try to hack it with a quick DataTable.AcceptChanges() the immediately call DataTable.RejectChanges() but every other time or so I would get a Application.Main() index out of range error.

Any help would be greatly appreciated. Thanks.
Jan 14 '09 #1
Share this Question
Share on Google+
2 Replies


Plater
Expert 5K+
P: 7,872
I think if you make changes to the bound datatable, you would want to call DataBind() again?
It might be competeing because that 3rd party control is not keeping its internal account of the data up to date with the datatable you provide
Jan 14 '09 #2

P: 2
Well tried looking into that Plater but didn't have any luck.

I did find a less elegant work-around. If I find the modified, added and deleted rows via DataTable.Select then I can AcceptChanges at the row level and this seems to work. e.g.:

DataRow[] deletedRows = DataSet.Tables[1].Select(null, null, DataViewRowState.Deleted);
foreach (DataRow _ddr in deletedRows)
{
_ddr.AcceptChanges();
}

DataRow[] addedRows = DataSet.Tables[1].Select(null, null, DataViewRowState.Added);
foreach (DataRow _ddr in addedRows)
{
_ddr.AcceptChanges();
}

DataRow[] updatedRows = DataSet.Tables[1].Select(null, null, DataViewRowState.ModifiedCurrent);
foreach (DataRow _ddr in updatedRows)
{
_ddr.AcceptChanges();
}

I'm sure there will be a little more overhead with this but shouldn't have any effect for what I'm doing with it. I won't have more than 2 or 3 modifications to AcceptChanges on at a time.

~Thanks
Jan 15 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.