具有TimeSpan DataType的DataView RowFilter [英] DataView RowFilter with TimeSpan DataType
问题描述
我尝试对数据类型为"TimeSpan"的列使用DataView
RowFilter
,如下所示:
I try to use the DataView
RowFilter
for a column with DataType "TimeSpan" as following:
dv.RowFilter = ("Convert([time],System.String) LIKE '17:12:00'")
我发现对于双零点的搜索参数"%17% or %12%
我必须使用一个单一的零点:%0%,效果很好,现在我不确定Convert(timespan, System.String)
格式....
我知道TimeSpan
具有特殊格式,例如(17,12,0)
或{17}{12}{0}
,但是作为未指定的转换为字符串,它应该是:hh:mm:ss
类似timespan.ToString()
-但使用DataView's
RowFilter我却不能让它工作!
I've found that the search Parameter "%17% or %12%
, for the double Zeros i have to use a single one: %0%, works fine, now im not sure about the Convert(timespan, System.String)
Format... .
I know that the TimeSpan
have a Special Format like (17,12,0)
or {17}{12}{0}
but as a not specified convert to string it should be: hh:mm:ss
like timespan.ToString()
- but with the DataView's
RowFilter i can't get this to work!
我正在将Visual Studio 2008 Pro与.NET 3.5配合使用.
I'm using Visual Studio 2008 Pro with .NET 3.5.
推荐答案
问题在于转换为字符串.它产生以非常奇怪的方式格式化的字符串.为了说明,让我们使用以下C#代码创建一个表:
The problem lies with the conversion to string. It produces a string formatted in a very strange way. To illustrate, let's create a table using this C# code:
var table = new DataTable();
table.Columns.Add("span", typeof(TimeSpan));
table.Rows.Add(new object[] { new TimeSpan(1, 2, 3) });
table.Rows.Add(new object[] { new TimeSpan(4, 5, 6) });
table.Columns.Add("asstring");
table.Columns["asstring"].Expression = "Convert(span, 'System.String')";
将其分配给网格控件后,它将如下所示:
After we assign it to a grid control, it will look like this:
在Microsoft自己的文档中,他们说要查看Expression
文档,以了解Convert(span, 'System.String')
在RowFilter
中的工作方式.这意味着它将TimeSpan完全转换为您在屏幕快照中看到的内容-01:02:03
变为PT1H2M3S
.
In Microsoft's own docs, they say to look at the Expression
docs to see how Convert(span, 'System.String')
works in RowFilter
. That means that it converts the TimeSpan to exactly what you see in the screenshot - 01:02:03
becomes PT1H2M3S
.
这篇关于具有TimeSpan DataType的DataView RowFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!