比较 DataView.RowFilter 中的日期?
我正在为一些相当愚蠢但显然很困难的事情摸不着头脑。
DataView dvFormula = dsFormula.Tables[0].DefaultView;
dvFormula.RowFilter = "'" + startDate.ToString("yyyyMMdd") + "' < EndDate OR EndDate = '19000101'";
dvFormula.Sort = "FromDate ASC";
结果是这样的:
无法执行“<”对 System.String 和 System.DateTime 的操作。
请告诉我解决这个问题的最佳方法是什么。
非常感谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要用#而不是撇号将日期括起来。
You need to wrap your dates with #, not apostrophes.
这就是解决方案。试试这个:
This is the solution. Try this:
根据您的数据提供程序,您可能需要使用
#
字符而不是'
字符转义日期。此外,我会将您的日期格式化为YYYY-MM-DD
格式,以确保它可以被正确识别为日期。Depending on your data provider, you may need to escape dates with the
#
character rather than the'
character. In addition, I would format your dates in the formatYYYY-MM-DD
to ensure it can be recognized as a date correctly.