Re: DataTable.Select with condition with Timespan values
- From: "Armin Zingler" <az.nospam@xxxxxxxxxx>
- Date: Tue, 10 Jul 2007 23:39:18 +0200
"Massimo" <massimo.frade@xxxxxxxxxx> schrieb
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.
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
.
- References:
- DataTable.Select with condition with Timespan values
- From: Massimo
- DataTable.Select with condition with Timespan values
- Prev by Date: Re: Maintain list of attached event handlers (.Net 1.1)
- Next by Date: Re: Maintain list of attached event handlers (.Net 1.1)
- Previous by thread: DataTable.Select with condition with Timespan values
- Next by thread: Windows Forms App as Console App
- Index(es):
Relevant Pages
|