Reputation: 61
How can I filter multiple combo boxes value in vb.net with SQL server query? All the comboboxes are user input. Example:
I have cboName.text, cboAge.text, cboAddress.text
SELECT name, age, address
FROM tbMaster
WHERE name = '" & cboName.text & "'
AND age = '" & cboAge.text & "'
AND address = '" & cboAddress.text & "'
If cboName is empty then it will display all Name.
What I did is:
IF cboName.text = '' AND cboAge.text = '' THEN
SELECT name,age,address FROM tbMaster
ELSEIFcboName.text <> '' AND cboAge.text = '' THEN
SELECT name,age,address FROM tbMaster WHERE name = '" & cboName.text & "'
ELSEIF cboName.text = '' AND cboAge.text <> '' THEN
SELECT name,age,address FROM tbMaster WHERE age = '" & cboAge.text & "'
ELSEIFcboName.text <> '' AND cboAge.text <> '' THEN
SELECT name,age,address FROM tbMaster WHERE name = '" & cboName.text & "' AND age = '" & cboAge.text & "'
and so on... Imagine if I have to filter 10 comboboxes.
How can I do it with SQL parameter effectively?
Thanks.
Upvotes: 0
Views: 53