After deleting the row of a DataTable, the error "Cannot access the row's information through a deleted row" appears, that is, deletedrowinaccessibleexception

Source: Internet
Author: User

"Cannot access information for this row through deleted rows" error after deleting row of DataTable
===========================================================

Use a DataTable. Rows[i]. Delete () When you delete a row and then access the table, the error "information that cannot access the row through a deleted row" appears. The reasons are as follows:

A DataTable is required after Delete (). The Acceptechanges () method confirms a complete deletion, because delete () only flags the status of the corresponding column as deleted, and it can be passed through a DataTable. RejectChanges () rollback to make the row undelete.

So if you want to delete the DataRow completely, you need to use either the Delete () and Acceptechanges () methods, or use a DataTable. The Rows.removeat (i) method is removed directly, where I represents the row index and one is a DataTable. Rows.remove (DataRow DR) deletes the specified line.

However, use a DataTable. Rows.removeat (i) Note that if you are using a DataTable continuously. Rows.removeat (0); a DataTable. Rows.removeat (1); This is not the deletion of the original table in 0, 1 rows, but the deletion of 0 rows, the original 1 lines will become 0 rows, so the DataTable. Rows.removeat (1) actually deletes 2 rows from the original table.

Therefore, we should use the DataTable with caution. Rows.removeat (i), to delete multiple rows, you can use Delete () consecutively and then confirm the deletion with the Acceptechanges () method.

After deleting the row of a DataTable, the error "Cannot access the row's information through a deleted row" appears, that is, deletedrowinaccessibleexception

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.