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.