Delete A able once

Source: Internet
Author: User

Directly Add code

 

Int proid1 = 0; foreach (datarow row1 in tables. rows) {If (convert. toint32 (row1 ["proid"]) = proid1) {row1.delete (); // tables. rows. remove (row1);} else {proid1 = convert. toint32 (row1 ["proid"]) ;}// submit the modified datatable tables. acceptchanges ();

If there are two data entries in the first column (505 506 507) that are deleted from column 6, the row with the value of Column 5 is retained.

Article 1: 505 3 3377 5 4
Article 2: 505 3 3377 6 5

Article 3: 506 3 3377 5 4

Article 5: 507 3 3377 5 4
Article 6: 507 3 3377 6 5

......................................

.....................................

 

Datatable. Rows. Remove cannot be used for loop traversal because it cannot damage its structure because it must be recycled.

 

Therefore, use tablerow. Delete () to mark it first, and then submit the modification using datatable. acceptchanges () after traversal.

 

Over

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.