How can I add this other property to my SQL Server query?

1

In ASP.NET WEB I am doing a search filtering for a table depending on the items you choose in 2 different dropdownlists. For now, I can make it work with one.

SQLTable = "SELECT * FROM Mitabla";
SQLTable += "WHERE ID='" + Dropdownlist1.SelectedItem.Value + "'";

How do I add this other property of the second Dropdownlist?:

  

Dropdownlist2.SelectedItem.Value

My ultimate goal is to filter the results in the table if I select both.

Help me fix it!

    
asked by KJSK 21.07.2018 в 05:42
source

1 answer

1

I recommend leaving a space in the consultations at the beginning of each line .-

SQLTable = " SELECT * FROM Mitabla ";
SQLTable += " WHERE ID='" + Dropdownlist1.SelectedItem.Value + "'";

That both (AND) are met

SQLTable += " AND PROPIEDAD ='" + Dropdownlist2.SelectedItem.Value + "'";

That one or the other is fulfilled (OR)

    SQLTable += " OR PROPIEDAD ='" + Dropdownlist2.SelectedItem.Value + "'";
// Si este es el caso recomiendo usar IN
    SQLTable = " SELECT * FROM Mitabla ";
    SQLTable += " WHERE ID IN('" + Dropdownlist1.SelectedItem.Value 
     + "'," +  Dropdownlist2.SelectedItem.Value + "')";
    
answered by 21.07.2018 / 06:31
source