Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

DataTable.Select with condition with Timespan values

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Massimo - 09 Jul 2007 15:42 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.