我有2个DataSet,如下所示,我需要将这些DataSet合并为1:
数据集1
date reason total
12 aug 2010 inactive 123
19 aug 2010 inactive 45
20 sep 2010 inactive 145
02 nov 2010 inactive 95
25 dec 2010 inactive 44
dataset2
date reason total
12 aug 2010 active 12
21 aug 2010 active 45
20 sep 2010 active 45
02 nov 2010 active 45
26 dec 2010 active 45
我可以使用Merge
方法合并DataSet,但是如何对DataSet进行排序以获得如下结果:
date reason total
12 aug 2010 inactive 123
12 aug 2010 active 12
19 aug 2010 inactive 45
21 aug 2010 active 45
20 sep 2010 inactive 145
20 sep 2010 active 45
02 nov 2010 inactive 95
02 nov 2010 active 45
25 dec 2010 inactive 44
26 dec 2010 active 45
答案 0 :(得分:4)
假设您希望按升序日期顺序和降序排列,可以使用DataView的Sort属性(DataView.Sort Property):
// Assuming the merged table is the first and only table in the DataSet.
DataView dv = new DataView(dataSet1.Tables[0]);
dv.Sort = "date, reason DESC";
我没有测试过这个 - 就在我的头顶。应该指出你正确的方向。