By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,180 Members | 1,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,180 IT Pros & Developers. It's quick & easy.

DataTable.Select condition with TimeSpan Values

P: n/a
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

Jul 9 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Massimo" <ma***********@tiscali.itwrote in message
news:11**********************@n60g2000hse.googlegr oups.com...
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
Jul 9 '07 #2

P: n/a
On 9 Lug, 16:53, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
"Massimo" <massimo.fr...@tiscali.itwrote in message

news:11**********************@n60g2000hse.googlegr oups.com...


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- 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

Jul 9 '07 #3

P: n/a
Hi,

"Massimo" <ma***********@tiscali.itwrote in message
news:11*********************@n60g2000hse.googlegro ups.com...
On 9 Lug, 16:53, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
>"Massimo" <massimo.fr...@tiscali.itwrote in message

news:11**********************@n60g2000hse.googleg roups.com...


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- 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 ?
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
Jul 9 '07 #4

P: n/a
On 9 Lug, 17:27, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Hi,

"Massimo" <massimo.fr...@tiscali.itwrote in message

news:11*********************@n60g2000hse.googlegro ups.com...


On 9 Lug, 16:53, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
"Massimo" <massimo.fr...@tiscali.itwrote in message
>news:11**********************@n60g2000hse.googleg roups.com...
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- 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 ?

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- 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...



Jul 9 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.