Some operations on datatable, such as generating another able from a certain datarow in a able, or adjusting the sort (SORT) method in the datatable, have a headache for me for a while.
Today, when reading the dataset member table in sdk2.0, I found that one of the merge methods is dataset. merge (datarow []) is used to directly merge datarow [] into the current dataset.
I started a test.
The first problem is to extract records of aid> 100 from the DTA table of DSA to the DTA of DSB.
The statement is as follows:
DSB. Merge (DSA. Tables ["DTA"]. Select ("aid> 100 ",""));
After running, the results are satisfactory. In DSB, there is another DTA table, and the records in the table are records of aid> 100.
The second problem is to change the record sorting method in the DTA table in DSA to aid DESC.
The statement is as follows:
DSA. Merge (DSA. Tables ["DTA"]. Select ("", "aid DESC "));
There was no response, and no data changes at all. I can't find a solution, but I just copied the DTA table and made it again.
The statement is as follows:
Datatable dtacopy = DSA. Tables ["DTA"]. Copy ();
DSA. Tables. Remove ("DTA ");
DSA. Merge (dtacopy. Select ("", "aid DESC "));
The running result is exactly what you want. Records in the DTA table have been sorted as required.
This method is suitable for grouping table data in dataset. I just don't know if the back-and-forth copy remove merge will be too costly.