C # able cannot access the information processing method of this row through the deleted row

Source: Internet
Author: User

The reason is as follows:

After the Delete () operation, you must use the able. AccepteChanges () method to confirm that the data is completely deleted, because Delete () only marks the status of the corresponding column as deleted,
You can also use datatable. RejectChanges () to roll back the row to cancel deletion.

To completely Delete datarow, you must use the Delete () and AccepteChanges () methods at the same time, or use the able. Rows. RemoveAt (I) method to directly Delete the datarow,
Where I indicates the row index, and datatable. Rows. Remove (DataRow dr) deletes the specified row.

However, when using datatable. Rows. RemoveAt (I), note that if you use able. Rows. RemoveAt (0); datatable. Rows. RemoveAt (1 );
In this case, the rows 0 and 1 in the original table are not deleted, but after the rows 0 are deleted, the original Row 1 becomes 0, so the datatable. rows. removeAt (1) actually deletes two rows of the original table.
Therefore, you should use datatable. Rows. RemoveAt (I) with caution. To Delete multiple Rows, you can use Delete () consecutively and then use the AccepteChanges () method to confirm the deletion.

Solution example:

Copy codeThe Code is as follows: List <string> lst = new List <string> ();
For (int I = 0; I <_ Table. Rows. Count; I ++)
{
If (_ Table. Rows [I]. RowState! = DataRowState. Deleted)
{
Lst. Add (_ Table. Rows [I] ["I _SL"]. ToString () = "0 "? "False": "true ");
}
}

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.