Changing a row during the RowChanging/RowChanged event

  • Thread starter Adrian Theodorescu
  • 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
 
M

Mike Bell]

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
 
A

Adrian Theodorescu

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
 
J

Jay B. Harlow [MVP - Outlook]

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
 
A

Adrian Theodorescu

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top