Assuming that you have a SqlCommand object which I will call
sqlCommand
and your 3 badly named comboBoxes are in order c1 - rent, c2 - gender, c3 - location (I'm using the shorthand because I could not be bothered to create 3 comboBoxes on my sandbox form)
Firstly you need to know which, if any, of the comboBoxes are set to the default of "ALL"...
var b1 = (c1 == "ALL");
var b2 = (c2 == "ALL");
var b3 = (c3 == "ALL");
These Booleans help to control what you are going to put into your WHERE clause. Because we are going to "add" to the where clause dynamically and because strings are immutable, use a stringBuilder to generate the query...
var whereQuery = new StringBuilder(" WHERE ");
Then add the sections into the WHERE clause based on the Boolean values...
if (b1)
{
whereQuery.Append("rentColum = @rent");
sqlCommand.Parameters.AddWithValue("@rent", c1);
}
if (b2)
{
whereQuery.Append((b1) ? " AND " : "");
whereQuery.Append("genderColumn = @gender");
sqlCommand.Parameters.AddWithValue("@gender", c2);
}
if (b3)
{
whereQuery.Append((b1 || b2) ? " AND " : "");
whereQuery.Append("locationColumn = @location");
sqlCommand.Parameters.AddWithValue("@location", c3);
}
Note that I'm building a parameterised query. Also note the way that " AND " is only added if there has been a filter added prior to c2, c3, (etc)
When you have finished building your where clause then add it to your SELECT query
selectQuery += whereQuery.ToString();
Please note, because of the lack of information in your question this answer is completely untested. There may be minor typing errors.