Solved

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

Posted on 2012-12-28
2
566 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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38727635
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
ID: 38728226
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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