I have the following code (a DataView that filtered by DateTime):
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:
Supposedly, only A should get filtered. But my code has A , B and C filtered as well, and only returns 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
.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.