gpt4 book ai didi

c# - 如何使用 DateTime 列过滤 DataTable?

转载 作者:太空宇宙 更新时间:2023-11-03 18:11:23 26 4
gpt4 key购买 nike

我想过滤一个数据表并且它有效,但如果我搜索 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();

账户开始时间:日期时间账户停止时间:日期时间帧 IP 地址:varchar

The error: The Operation 'Like' could not to System.DateTime and System.String execute.

我该怎么做?

最佳答案

像这样尝试DateComparision in RowFilter

string filter = $"DateFrom > '{daDateFrom}' AND DateTo <= '{daDateTo}'";
tb.Select(filter)

或来自DataRow filter Examples

Date values are enclosed within sharp characters # #. The date formatis the same as is the result of DateTime.ToString() method forinvariant or English culture.

[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

关于c# - 如何使用 DateTime 列过滤 DataTable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14498559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com