[英]Filter DateTime in DataView does not filter minutes and second
I have the following code (a DataView that filtered by DateTime):我有以下代码(由 DateTime 过滤的 DataView):
dv = new DataView(
dataTable1,
"DateTime >= '" + Convert.ToDateTime("7/5/2011 9:21:00 AM") + "'",
"ID ASC", DataViewRowState.CurrentRows);
My datatable1 consist of the following data in the DateTime column:我的 datatable1 包含 DateTime 列中的以下数据:
Supposedly, only A should get filtered.据说,只有A应该被过滤。 But my code has A , B and C filtered as well, and only returns D .但我的代码也过滤了A 、 B和C ,并且只返回D 。
What is wrong?怎么了?
Try this尝试这个
dv = new DataView(
dataTable1,
"CONVERT(DateTime, System.DateTime) >= '" + Convert.ToDateTime("7/5/2011 9:21:00 AM") + "'",
"ID ASC", DataViewRowState.CurrentRows);
Try enclosing the date string with #
.尝试用#
括起日期字符串。 For example:例如:
dv = new DataView(
dataTable1,
"DateTime >= #" + Convert.ToDateTime("7/5/2011 9:21:00 AM") + "#",
"ID ASC", DataViewRowState.CurrentRows);
Remove the convert.todatetime
.删除convert.todatetime
。
You can try this你可以试试这个
String date1 =String.Empty ;
date1 = "7/5/2011 9:21:00 AM";
dv = new DataView(dataTable1,"DateTime >= #" + date1 + "#", "ID ASC", DataViewRowState.CurrentRows);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.