I am using BindingSource.Filter to filter data on my datagridview. I used the following code:
BindingSource bs = new BindingSource();
bs.DataSource = datagridview1.DataSource;
bs.Filter = "columnName like '%" + textBox1.Text + "%'";
datagridview1.DataSource = bs;
This code works. But when I filter data on a two-word column, the code does not work anymore. I tried putting apostrophe on those words like 'column name' like '%" + tbFilter.Text + "%'
, but this does not help. Please help me find the right code to filter data on my columns.
Enclose column name in
[]
:I think it's always a good idea even if your column names are one-word.