Datatable. Merge () is used to solve a sorting problem.

Source: Internet
Author: User

First, make it clear that,Datatable does not support sorting.
There is already unordered data in a datatable (DT). To sort data, I have two methods:

Method 1:
You can create a list to store the values of the DT primary key columns in order. Then, you can use the datatable. Merge method to create a list.

1 Strongtypeddatatable tempdt;
2 // Make tempdt have DT schema and Constraint
3 Tempdt =   New Strongtypeddatatable ();
4 Foreach ( String Key In List)
5 {
6 // If some Columns cannot be empty, newrow ()-> assign key value-> Add (DR ).
7 Tempdt. Rows. Add (key, Null .);
8 }
9 // After merging, the Order in tempdt will be maintained.
10 Tempdt. Merge (DT );
11 DT = Tempdt;

Method 2:
Idea: dataview supports sorting, while dataview objects have methods.TotableI have never tried it. Anyone who has understood the totable principle or has the chance to use it will give an answer :)

P.s pig's first post.

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.