I use this working code to search from textbox any partial word but just inside one column (Firstname) and return the filtered result inside DataGridView
:
ContactsTableBindingSource.Filter = String.Format("{0} LIKE '%{1}%'", "Firstname", TextBox1.Text)
How can I search inside others columns?? I've tried some codes like this:
ContactsTableBindingSource.Filter = String.Format("{0} LIKE '%{1}%'", "Firstname" OR ContactsTableBindingSource.Filter = String.Format("{0} LIKE '%{1}%'", "Lastname", TextBox1.Text)
ContactsTableBindingSource.Filter = String.Format("{0} LIKE '%{1}%'", "Firstname" OR "Lastname", TextBox1.Text)
But doesn't works! Can anybody show me which is the correct syntax to search any partial word at any column?
Your syntax is incorrect. Boolean expression is actually allowed inside Filter
property. Example:
String.Format("{0} LIKE '%{2}%' OR {1} LIKE '%{2}%'", "Firstname", "Lastname", TextBox1.Text)