如何根据 TimeSpan 值过滤 DataColumn?
使用 C#.NET 进行编程。我有一个DataTable
,其中有一列名为Time,其类型为System.TimeSpan
。当我在 DataGridView
中显示 DataTable
时,我想过滤掉所有未列出时间的条目。我已尝试以下方法但无济于事。你能帮忙吗?
DataView myDataView = new DataView(SomeDataTable);
myDataView.RowFilter += "Time >= 1"; // doesn't work
myDataView.RowFilter += "Time >= #00:00:01#"; // doesn't work
myDataView.RowFilter += "Time <> ''"; // doesn't work
myDataView.RowFilter += "Time <> ''"; // doesn't work
Programming in C#.NET. I have a DataTable
with a column named Time which is of type System.TimeSpan
. When I display the DataTable
in a DataGridView
I want to filter out all the entries that don't have a time listed. I have tried the following but to no avail. Can you help?
DataView myDataView = new DataView(SomeDataTable);
myDataView.RowFilter += "Time >= 1"; // doesn't work
myDataView.RowFilter += "Time >= #00:00:01#"; // doesn't work
myDataView.RowFilter += "Time <> ''"; // doesn't work
myDataView.RowFilter += "Time <> ''"; // doesn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了...
I found it...
如果有人遇到这个恼人的问题,不幸的是没有好的解决方案。
看来使用
System.TimeSpan
过滤DataTable
不起作用。我使用的解决方案是将 SQL 中的列类型从
Time(0)
(或其他)更改为NVARCHAR(8)
,然后您可以应用逻辑 :10:32:15) 转换回
System.TimeSpan
就这么简单然后将 sql 表中的字符串从
hh:mm:ss
( 这两天我一直在想这个问题,希望能有所帮助:)If someone bump into this annoying problem, unfortunately there is no good solve.
It seams that filter
DataTable
withSystem.TimeSpan
is not working.The solution I use is to change the type of the column in the SQL to
NVARCHAR(8)
fromTime(0)
(or whatever) and then you can just apply logic upon it like so:Afterward convert string from the sql table from
hh:mm:ss
(10:32:15) back intoSystem.TimeSpan
is as easy as:I break my head on this for two days, I hope it will help :)