Baka Musky

Baka Musky

  • 2.1k
  • 10
  • 418

Query for a combobox and textbox to search within a datagrid

Jul 14 2017 7:03 AM
Hey everyone,

I currently nearly finished a simple application, but my query doesnt work. I have a combobox and a textbox. By selecting a column name from the combobox, I want to be able to search in the textbox within that column. Anyone that can fix this query? I've been trying alot but havent had any succes yet.
SqlCommand command = new SqlCommand("SELECT * FROM dbo.Kwartaal " +
"WHERE '" + searchField + "' LIKE '% " + txtSearch.Text + "%' ", con);
Edit: searchField is my string that gets filled by selecting the column. txtSearch is the textbox obviously. 

Answers (6)