Changing a row during the RowChanging/RowChanged event

  • Thread starter Thread starter Adrian Theodorescu
  • Start date Start date
A

Adrian Theodorescu

Hi All,

Does anybody know how can I make changes to the DataRow that is being
modified during the RowChanging or (RowChanged) event of the DataTable
class? For example, I have a column named "MODIFIED", which I want to set to
1 each time the row is changed. I tried to use code like:

protected void RowChanging(object sender, System.Data.DataRowChangeEventArgs
e) {
e.Row["MODIFIED"] = 1;
}

The code above throws an exception. The message is "Cannot change a proposed
value in the RowChanging event. Please help.

Regards,
Adrian
 
I'm not sure why you would want to do this since your RowState should
contain the information you're trying to change. e.Row.RowState should tell
you it's been modified. I believe you're not going to get past that
exception with your task, since it would endlessly fire itself.

Mike
 
This is required by application logic (I need to save the "modified" state
into the record). But never mind the name of the column. The question is how
can I modify a field in a row during the RowChanging event?

Adrian

Mike Bell] said:
I'm not sure why you would want to do this since your RowState should
contain the information you're trying to change. e.Row.RowState should tell
you it's been modified. I believe you're not going to get past that
exception with your task, since it would endlessly fire itself.

Mike

Adrian Theodorescu said:
Hi All,

Does anybody know how can I make changes to the DataRow that is being
modified during the RowChanging or (RowChanged) event of the DataTable
class? For example, I have a column named "MODIFIED", which I want to
set
to
1 each time the row is changed. I tried to use code like:

protected void RowChanging(object sender, System.Data.DataRowChangeEventArgs
e) {
e.Row["MODIFIED"] = 1;
}

The code above throws an exception. The message is "Cannot change a proposed
value in the RowChanging event. Please help.

Regards,
Adrian
 
Adrian,
Have you tried using the ColumnChanging or ColumnChanged events instead of
the RowChanging & RowChanged events?

Note: I have had limited success with the RowChanged event, however you need
to be certain which Actions you look for...

Hope this helps
Jay
 
This is required by application logic (I need to save the "modified" state
into the record). But never mind the name of the column. The question is how
can I modify a field in a row during the RowChanging event?

Adrian

Mike Bell] said:
I'm not sure why you would want to do this since your RowState should
contain the information you're trying to change. e.Row.RowState should tell
you it's been modified. I believe you're not going to get past that
exception with your task, since it would endlessly fire itself.

Mike

Adrian Theodorescu said:
Hi All,

Does anybody know how can I make changes to the DataRow that is being
modified during the RowChanging or (RowChanged) event of the DataTable
class? For example, I have a column named "MODIFIED", which I want to
set
to
1 each time the row is changed. I tried to use code like:

protected void RowChanging(object sender, System.Data.DataRowChangeEventArgs
e) {
e.Row["MODIFIED"] = 1;
}

The code above throws an exception. The message is "Cannot change a proposed
value in the RowChanging event. Please help.

Regards,
Adrian
 
Back
Top