|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
What could be causing this while updating a DataTable?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 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 > > Are you handling any adapter or datatable events? I am wondering if you No, no events/handlers of any kind. Exception is coming from inside the > are handling an event that is firing here and your handler is throwing the > exception. Update method. > If you have a small set of complete code to reproduce the problem that I appreciate it. I ended up getting rid of the adapter and doing things > would be helpful.. 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 |
|||||||||||||||||||||||