此处以表dt2中的keyIndex列(int类型)为例
1、通过linq来实现
int maxKeyIndex = dt2.AsEnumerable().Select(t => t.Field("keyIndex")).Max();
Linq语法:
点击打开链接
2、
通过
Compute方法来实现
int ee = (int)dt2.Compute("Max(keyIndex)", "true");
Compute方法:点击打开链接
3、
通过
Select方法来实现
int rr = (int)dt2.Select("", "keyIndex DESC")[0]["keyIndex"];
Select方法:点击打开链接
4、转List
将DataTable中需要排序的列转List,然后通过list的Sort()方法来排序,默认值升序的即排序完成后,list中的最后一个是最大值。
List简介