views:

20

answers:

2

I am scratching my head over something rather stupid yet apparently difficult.

DataView dvFormula = dsFormula.Tables[0].DefaultView;
dvFormula.RowFilter = "'" + startDate.ToString("yyyyMMdd") + "' < EndDate OR EndDate = '19000101'";
dvFormula.Sort = "FromDate ASC";

The result is this:

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

Please tell me what the best way to solve this problem would be.

Much appreciated!

A: 

Depending on your data provider, you may need to escape dates with the # character rather than the ' character. In addition, I would format your dates in the format YYYY-MM-DD to ensure it can be recognized as a date correctly.

Ryan Brunner
+1  A: 

You need to wrap your dates with #, not apostrophes.

dvFormula.RowFilter = "#" + startDate.ToString("MM/dd/yyyy") + "# < EndDate OR EndDate = #1/1/1900#";

Dan
You're right it was the #. But the crucial part is that the dateformat needs to be the same as the one your system settings are using. How stupid is that... so now I'm using `startDate.ToShortDateString()`. Thanks m8!
Peter
Didn't know about the date format matching system settings. Thanks for educating me and anyone else who reads this!
Dan