Groups | Blog | Home
all groups > dotnet ado.net > july 2007 >

dotnet ado.net : Can't modify DataRow during RowChanged event


Amir Tohidi
7/5/2007 5:28:00 AM
Hi

I need to trap the insertion of a new row into a DataTable while it is being
filled by a data adaptor. I am trapping the RowChanged event and using the
following syntax to try and modify the row:

e.Row.ItemArray(index) = newValue

The line above executes without errors BUT my change is actually applied to
the DataRow!

Amir Tohidi
7/5/2007 5:38:00 AM
Sorry, the penultimate paragpraph should read:

The line above executes without errors BUT my change is NOT BEING applied to
the DataRow!


[quoted text, click to view]
Milosz Skalecki [MCAD]
7/5/2007 6:58:04 AM
Hi there,

Use Row directly. Also make sure you change the value only when it hass been
added:

protected void table_RowChanged(object sender, DataRowChangeEventArgs e)
{
if (e.Action == DataRowAction.Add)
e.Row[itemIndex] = newValue;
}

Hope it helps
--
Milosz


[quoted text, click to view]
Amir Tohidi
7/5/2007 9:58:02 AM

Thanks Martin & Milosz - your comments helped me solve the problem.

[quoted text, click to view]
martin marinov
7/5/2007 1:25:13 PM
Hello Amir,

Actually the ItemArray is a copy of the cells' values of the TableRow
the proper code should be e.Ro(index) = newValue

In this case the update should run without problems

Regards
Martin

[quoted text, click to view]

AddThis Social Bookmark Button