Search code examples
c#ms-accesscheckboxbooleanrowfilter

Rowfilter and checkbox with access C#


I would like to filter an ms access database and have a preview in a DataGridView. Actually, I'm able to filter with combobox or textbox like this :

dvhotline.RowFilter = "Quand LIKE '%" + textBox1.Text + "%' AND Qui LIKE '%" + textBox2.Text + "%' AND Quoi LIKE '%" + textBox3.Text + "%' AND Pb LIKE '%" + textBox5.Text + "%' AND Solutions LIKE '%" + textBox4.Text + "%' AND Statut LIKE '%" + comboBox1.Text + "%' AND Axi = '%"+checkBox1.Checked+"%' ";

But I have a column with checkbox true/false.

How can I filter with a checkbox like (I know it's false but it's my only idea) :

...AND columnname LIKE '"+checkbox1.checked+"'

Thank you ;)


Solution

  • In SQL the boolean is stored as bit datatype (so either 1 or 0), so you need to do something like this:

    AND columnname = "+(checkbox1.checked ? "1" : "0")