C # DataTable cannot access the line's information processing methods through deleted rows _c# tutorial

Source: Internet
Author: User
The reasons are as follows:

The DataTable is required after Delete (). The Acceptechanges () method confirms a complete deletion, because delete () simply flags the status of the corresponding column as deleted.
You can also pass the DataTable. RejectChanges () rollback, causing the row to be removed.

If you want to completely remove DataRow, you need the Delete () and acceptechanges () methods to be used at the same time, or in a DataTable. Rows.removeat (i) method is directly deleted,
Where I represents the row index, and one is the DataTable. Rows.remove (DataRow DR) deletes the specified line.

But use a DataTable. Rows.removeat (i) Note that if the DataTable is used continuously. Rows.removeat (0), DataTable. Rows.removeat (1);
This is not the deletion of the original table of 0, 1 rows, but delete 0 rows, the original 1 rows into 0 rows, so the DataTable. Rows.removeat (1) actually deletes 2 rows from the original table.
So be careful with the DataTable. Rows.removeat (i), to delete multiple rows, you can use Delete () consecutively, and then use the Acceptechanges () method to confirm the deletion.

Solution Example:

Copy Code code 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");
}
}
Related Article

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.