如何在c#.net中对数据表进行排序 [英] How To Sort Datatable in c#.net

查看:176
本文介绍了如何在c#.net中对数据表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello, I have Datatable like

   Date        Preferance
30/07/2011      0
02/03/2011      1
10/12/2011      2
01/12/2011      3


I am trying to sort prefenaces column as per date(Samllest date will get first prefenace),i am trying to get values in datatable like

 Date       Preferance
30/07/2011      1
02/03/2011      0
10/12/2011      3
01/12/2011      2

i am trying to sorts dates in datatable,
i have tried
Datatable.Select(filterExp, sortExp, DataViewRowState.CurrentRows)
and
Datatable.DefaultView.Sort = "ID ASC"; 

but both this are not working this method takes date as string

What to do for this,please help </pre>

推荐答案

为什么使用 ID ASC 。您应该使用 Preferance ASC

Why you are using ID ASC. You should use Preferance ASC
Datatable.DefaultView.Sort = "Preferance ASC"; 


我认为这是对数据表进行排序的最简单方法..



I think this is the easiest way to sort a Datatable..

dt.DefaultView.Sort = "Parameter_Name";
dt = dt.DefaultView.ToTable();


[ ^ ]就是我如何解决这个问题。
This[^] is how I'd solve this problem.


这篇关于如何在c#.net中对数据表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆