Search code examples
c#dataviewrowfilter

Unable to Have (-) Dash in DataView Filter C#


I have a column in datatable where the columname is "last-updated" and I am trying to use the column name with filter like below

dv.RowFilter = " (last-updated >= #" + Convert.ToDateTime(dateTimePickerStart.Text).ToString("MM/dd/yyyy") + "# And Date <= #" + Convert.ToDateTime(dateTimePickerEnd.Text).ToString("MM/dd/yyyy") + "# ) ";

When I try to build I am getting

"Cannot find colum [last]".

I have tried to add single quote arrounding the column name but still not working.


Solution

  • I think - acts like an arithmetic operator in your case and this RowFilter thinks that last and updated as a two different columns and you try to calculate their differences.

    Just wrap them with [] as [last-updated] in it should be fine.