Difference between rows. removeat (I) and rows (I). Delete in the datatable

Source: Internet
Author: User
// Delete is not really deleted. It only changes the rowstate of the row to rowstate. Delete (there are still so many rows. Count)
// Remove is actually deleted from the datatable

For example:

DS. Tables [0]. Rows [I]. Delete ();
DS. Tables [0]. Rows. removeat (I );

The two are different.
1. Use mydatatable. Rows. removeat (I) to delete rows.
2. To use mydatatable. Rows (I). Delete, you must use mydatatable. acceptchanges to update the data to the database.

The first method is relatively simple. but do not use mydatatable in the loop. rows. removeat (I ). because after each row is deleted. the I value increases, but the number of rows decreases. this will definitely cause errors.
Therefore, you need to traverse the data in reverse order when using the Remove Method.
Int COUNT = Ds. Tables [0]. Rows. count;
For (INT I = count-1; I> = 0; I --)
{
DS. Tables [0]. Rows. removeat (I );
}

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.