DataTable.Select condition with TimeSpan Values

  • Thread starter Thread starter Massimo
  • Start date Start date
M

Massimo

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
 
Massimo said:
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?

Not really, as a matter of fact I think that you cannot use it. HOUR is of
type TimeSpan, and unless it define a comparision with an integer (I do not
think so) you cannot use select.

What if you isntead of using TimeSpan use an integer to just hold the hours?
then it will be an integer and you will be able to use Select
 
Not really, as a matter of fact I think that you cannot use it. HOUR is of
type TimeSpan, and unless it define a comparision with an integer (I do not
think so) you cannot use select.

What if you isntead of using TimeSpan use an integer to just hold the hours?
then it will be an integer and you will be able to use Select- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

i could create a conversion between a TimeSpan ( i.e. 10:35:20 ) into
an integer 1035,20 but tell me , why i don't read restrictions of any
type about timeSpan values into MSDN ?
i'm confident that exists ( and, if not , will ...) a way to use
Select with Timespan comparison or, at least a special char like # for
Dates to convert strings in timespan.
I cannot beleave that i'm the first to use Select method with timespan
params...
In any case, thank you

Massimo
 
Hi,

Massimo said:
i could create a conversion between a TimeSpan ( i.e. 10:35:20 ) into
an integer 1035,20 but tell me , why i don't read restrictions of any
type about timeSpan values into MSDN ?

This is not a problem related to TimeSpan, it's more related to the way
Select works, Select just do a comparison between the value of the column
and the value provided, as TimeSpan do not provide conversion from either
string nor integer you cannot do it.

i'm confident that exists ( and, if not , will ...) a way to use
Select with Timespan comparison or, at least a special char like # for
Dates to convert strings in timespan.

I do not think so, but in case you find it post back your solution
 
Hi,









This is not a problem related to TimeSpan, it's more related to the way
Select works, Select just do a comparison between the value of the column
and the value provided, as TimeSpan do not provide conversion from either
string nor integer you cannot do it.


I do not think so, but in case you find it post back your solution- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

OK,

into the MSDN Page related to DataTable.Select method there is an
example :

expression = "Date > '1/1/00'";

in this case the value is a String but i expect that the filter
compares two dates. i find strange that is non possible to do the same
thing with an hour instead a Date...
 
Back
Top