Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

asp.net

I'm trying to filter my DataView by date:

DataTable dt = GetTableData();
DataView dvEvents = dt.DefaultView;
dvEvents.RowFilter = "date > #" + DateTime.Now.ToString() + "#";

But I'm getting this error:

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

I've also tried DateTime.Now.ToString("MM/dd/yyyy"), and I get the same error.

What am I doing wrong here?

like image 994
Steven Avatar asked Dec 26 '22 05:12

Steven


1 Answers

If you are using string values you need to replace the # with '.

For example:

dvEvents.RowFilter = "date > '" + DateTime.Now.ToString() + "'";

See this reference

like image 55
Jack Pettinger Avatar answered Feb 01 '23 12:02

Jack Pettinger