views:

265

answers:

1

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?

+2  A: 

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.

Jason Kester
No it doesn't. Even when I hard code the string to something such as string s = "column name = 'test'" I get that error.then i use this string s as the row filter iike so: dataview.rowfilter = s;
gsirianni
I'v eseen the stirng.Format method used on some of the online posts. I'll give it a shot.
gsirianni
Why then do you think that this line is the source of your problem? If you can set .RowFilter = "mycol like 'fishies'" and it still throws,then your next step is to remove the line entirely and see what happens. My suspicion is it will then throw on whatever line happened to float up to the same position. In other words, look at the lines above and below.
Jason Kester
iT WORKED! Thank you very much.
gsirianni