Home All Groups Group Topic Archive Search About

What could be causing this while updating a DataTable?

Author
2 Feb 2006 1:25 AM
Benton
Hi there,

I am getting this exception

"Deleted row information cannot be accessed through the row"

when trying to update a datatable with an adapter:

mAdapter.Update(mTable);  <== exception here

After struggling with this for hours, I am now looking for a more generic
answer, i.e., does anyone know the possible scenarios in which this
exception might occur inside the Update method. What "mistake" on my side
could be triggering it.

The exception usually happens if I:

1) Delete all rows in the table:

            for (int i = 0; i < mTable.Rows.Count; i++)
                mTable.Rows[i].Delete();

2) Add new rows to the table => mTable.Rows.Add(newRow);

3) Call the update method => adapter.Update();

Thanks in advance for any opinions,

-Benton

Author
2 Feb 2006 9:50 PM
Marina Levit [MVP]
Are you handling any adapter or datatable events? I am wondering if you are
handling an event that is firing here and your handler is throwing the
exception.

If you have a small set of complete code to reproduce the problem that would
be helpful..

Show quote
"Benton" <no@spam.com> wrote in message
news:OKdYSe5JGHA.1544@TK2MSFTNGP11.phx.gbl...
> Hi there,
>
> I am getting this exception
>
> "Deleted row information cannot be accessed through the row"
>
> when trying to update a datatable with an adapter:
>
> mAdapter.Update(mTable);  <== exception here
>
> After struggling with this for hours, I am now looking for a more generic
> answer, i.e., does anyone know the possible scenarios in which this
> exception might occur inside the Update method. What "mistake" on my side
> could be triggering it.
>
> The exception usually happens if I:
>
> 1) Delete all rows in the table:
>
>            for (int i = 0; i < mTable.Rows.Count; i++)
>                mTable.Rows[i].Delete();
>
> 2) Add new rows to the table => mTable.Rows.Add(newRow);
>
> 3) Call the update method => adapter.Update();
>
> Thanks in advance for any opinions,
>
> -Benton
>
Author
2 Feb 2006 10:12 PM
Benton
> Are you handling any adapter or datatable events? I am wondering if you
> are handling an event that is firing here and your handler is throwing the
> exception.

No, no events/handlers of any kind. Exception is coming from inside the
Update method.

> If you have a small set of complete code to reproduce the problem that
> would be helpful..

I appreciate it. I ended up getting rid of the adapter and doing things
manually, i.e., iterating the datarows, inspecting the RowState and issuing
insert, update, and delete commands accordingly. For the delete command I
used the 'DataRowVersion.Original' parameter when feeding row column values
to the command parameters (somehow the adapter was not doing this I guess),
and everything went fine. <Sigh> I didn't like the adapter very much in the
first place. ;-)

Best regards,

-Benton

AddThis Social Bookmark Button