Question

My application has a populated datatable and binds it to a ddatagridview by setting the datasource property.

At run time I want to filter this table. When the user clicks a button I run the following code:

dataManager.VDMSTables.DataTable.DefaultView.RowFilter = column + " LIKE '%" + criteria + "%'";

All the classes are populated correctly. At runtime when I reach this line I get the following error message:

Syntax error: Missing operand after 'Data' operator. The variables that I use to build the rowfilter are correctly populated. Even when I hard code a string I still get this same error. Why?

Was it helpful?

Solution

What does the actual string you're constructing look like when you view it in the debugger? The word "Data" doesn't show up in there, does it?

If so, then it's telling you that Data is a reserved word and you need to mark it as such. As in:

dataManager.VDMSTables.DataTable.DefaultView.RowFilter 
    = String.Format("[{0}] LIKE '%{1}%'"
        , column
        , YourSingleQuoteEscape(criteria) );

That will produce:

"[Data] like '%strawberries%'"

... which should parse correctly for your RowFilter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top