在DataView.RowFilter中比较日期? [英] Compare dates in DataView.RowFilter?

查看:209
本文介绍了在DataView.RowFilter中比较日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  DataView dvFormula = dsFormula.Tables [0]。默认视图; 
dvFormula.RowFilter ='+ startDate.ToString(yyyyMMdd)+'< EndDate OR EndDate ='19000101';
dvFormula.Sort =FromDate ASC;

结果是这样的:


无法在System.String和System.DateTime上执行'<'操作。


请告诉我



非常感谢!

解决方案

p>你需要用#而不是撇号来包装日期。

  dvFormula.RowFilter =#+ startDate.ToString( MM / dd / yyyy)+#< EndDate OR EndDate =#1/1/1900#; 


I am scratching my head over something rather stupid yet apparently difficult.

DataView dvFormula = dsFormula.Tables[0].DefaultView;
dvFormula.RowFilter = "'" + startDate.ToString("yyyyMMdd") + "' < EndDate OR EndDate = '19000101'";
dvFormula.Sort = "FromDate ASC";

The result is this:

Cannot perform '<' operation on System.String and System.DateTime.

Please tell me what the best way to solve this problem would be.

Much appreciated!

解决方案

You need to wrap your dates with #, not apostrophes.

dvFormula.RowFilter = "#" + startDate.ToString("MM/dd/yyyy") + "# < EndDate OR EndDate = #1/1/1900#"; 

这篇关于在DataView.RowFilter中比较日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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