通过使用datatable降序来生成日期顺序列表 [英] Make list of date order by descending using datatable

查看:105
本文介绍了通过使用datatable降序来生成日期顺序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从代码中列出日期:



table.Rows.Add(CDate(ud(i))。ToString(MMMM yyyy)



并使用以下方法对其进行排序:



I have date listed from a code:

table.Rows.Add(CDate(ud(i)).ToString("MMMM yyyy")

and sorted it using:

Dim view As DataView = table.DefaultView
       view.Sort = "Period Cover ASC"
       Dim sortedDate As DataTable = view.ToTable()









2016年1月
2015年12月

2015年11月

2015年1月

2015年2月

2015年3月
Arpil 2015

2015年5月

2015年6月

2015年7月

Agusut 2015
2015年9月

2015年10月





但我得到:





2015年1月

2016年1月

2015年2月

3月2015

Arpil 2015

2015年5月

2015年6月

2015年7月
Agusut 2015

2015年9月

2015年10月

2015年11月

2015年12月


它还没有按顺序排列。任何帮助?





January 2016
December 2015
November 2015
January 2015
February 2015
March 2015
Arpil 2015
May 2015
June 2015
July 2015
Agusut 2015
September 2015
October 2015


but I get:


January 2015
January 2016
February 2015
March 2015
Arpil 2015
May 2015
June 2015
July 2015
Agusut 2015
September 2015
October 2015
November 2015
December 2015

It is still not in order. any help?

推荐答案

如果我读得正确,你将它们排序为字符串 - 我将它们转换为日期或具有特定比较器的自定义对象(可能实现IComparable)对它们进行排序



也许在Linq中有一种方法你可以动态构建和比较日期对象 - 我确定有,我只是想过关于它太多了
if I read this correctly, you're sorting these as strings - I'd be converting them to dates or a custom object with a specific comparer (possible implementing IComparable) to sort them

Maybe there's a way in Linq you can build and compare date Objects on the fly - Im sure there is, I just havnt thought about it too much more


这篇关于通过使用datatable降序来生成日期顺序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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