Solved

Cannot perform '<' operation on System.DateTime and System.Double.

Posted on 2012-12-28
2
561 Views
Last Modified: 2012-12-31
Cannot perform '<' operation on System.DateTime and System.Double.


 dvholidays = New DataView(dtholidays, "Date <" & enddate.AddDays(1).ToShortDateString & " and Date >" & startdate.AddDays(-1).ToShortDateString & "", "", DataViewRowState.CurrentRows)

Open in new window

0
Comment
Question by:runnerjp2005
2 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
if you check the string you build, you would see that it would be a "math expression"

you need to put quotes:
 dvholidays = New DataView(dtholidays, "Date < '" & enddate.AddDays(1).ToShortDateString & "' and Date > '" & startdate.AddDays(-1).ToShortDateString & "' ", "", DataViewRowState.CurrentRows)

Open in new window


this will resolve the error, but it will eventually result in bad results if the comparison of the values is not "expected".

see this article:
http://www.experts-exchange.com/Database/Miscellaneous/A_1499-DATE-and-TIME-don%27t-be-scared-and-do-it-right-the-first-time.html
it's not about data views, so it won't show the relevant solutions, but ideas to think at least.
as I indicated in your previous question, you may need to solve this differently.
make so that the "date" field in the dataset is returned as string in the format 'YYYYMMDD' to make your > and < conditions to work ...
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
As suggested in your other question, use CDate function

 dvholidays = New DataView(dtholidays, "Date < CDate('" & enddate.AddDays(1).ToShortDateString & "') and Date > CDate('" & startdate.AddDays(-1).ToShortDateString & "') ", "", DataViewRowState.CurrentRows)

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now