Hi to All,
i'm using C# in .NET 2.0 and i have a DataTable A with a column of
type TimeSpan used to store HOUR info.
I'm trying to filter my DataTable A selecting only rows that have the
column HOUR > ....
if i try to Call A.Select( " HOUR > '10:30:00' " ) i receive an
error
( cannot compare TimeSpan with String ...)
if i try to call A.Select ( " HOUR > 10:30:00 " ) i receive an error
( invalid token : )
if i try to call A.Select ( " HOUR >
Convert('10:30:00',System.TimeSpan) " ) i receive an error ( string
'10:00:00' is not a valid TimeSpan )
if i try to call A.Select ( " HOUR > #10:30:00#" ) i receive an error
( Cannot compare TimeSpan with Date )
...
...
i think that i missed only the right way to write my filter.
Can someone help me?
Thank you in advance.
Regards,
Massimo
Armin Zingler - 10 Jul 2007 22:39 GMT
> Hi to All,
> i'm using C# in .NET 2.0 and i have a DataTable A with a column of
[quoted text clipped - 20 lines]
>
> Thank you in advance.
Debugging this issue, the conversion turns out to be the job of
"System.Xml.XmlConvert.ToTimeSpan(String s)". As [F1] doesn't reveal the
format required, I used
XmlConvert.ToString(TimeSpan.FromHours(10.5))
to find it out. Result is:
"PT10H30M"
Using this format, the conversion works... BUT, the > operator doesn't seem
to work with TimeSpan values:
A.Select("HOUR > CONVERT('PT10H30M','System.TimeSpan')")
The exception message says that the > operator can not be used with a
System.TimeSpan and a System.TimeSpan value. This limitation is not
described in the documentation. Maybe somebody has a workaround... (maybe
another column containing comparable ticks (Long) instead of a timespan;
or a simple loop instead of calling Select)
Armin