我如何使用DateTime列过滤DataTable?

Tar*_*sov 1 c# datatable listview datarow

我想过滤数据表并且它可以工作但是如果我搜索DateTime我会收到错误.

这是我的代码.我做错了什么?

 DataTable tb = DataBaseManager.GetRadiusDataTable(radiusconnectionstring, "marksullivan"); 

DataRow[] filteredRows = tb.Select("AcctStartTime LIKE '%" + searchstring + "%' OR AcctStopTime LIKE '%" + searchstring + "%' OR FramedIPAddress LIKE '%" + searchstring + "%'");
tb = filteredRows.CopyToDataTable();
this.ListView.DataSource = tb;
this.ListView.DataBind();
Run Code Online (Sandbox Code Playgroud)

AcctStartTime:datetime AcctStopTime:datetime FramedIPAddress:varchar

The error: The Operation 'Like' could not to System.DateTime and System.String execute.
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Rav*_*dag 8

尝试在RowFilter中使用这个DateComparision

 string filter = "DateFrom > '" + daDateFrom + "' AND DateTo <= '" + daDateTo + "'";
tb.Select(filter)
Run Code Online (Sandbox Code Playgroud)

或者从DataRow过滤器示例

日期值包含在##中.日期格式与DateTime.ToString()方法的结果相同,用于不变量或英语文化.

[C#]

dataView.RowFilter = "Date = #12/31/2008#"          // date value (time is 00:00:00)
dataView.RowFilter = "Date = #2008-12-31#"          // also this format is supported
dataView.RowFilter = "Date = #12/31/2008 16:44:58#" // date and time value
Run Code Online (Sandbox Code Playgroud)