Where That Selects All?
Solution 1:
Set SelectedItemFromComboBox to null and change your query to
SELECT*FROM Table1
WHERE Column1 = SelectedItemFromComboBox
or SelectedItemFromComboBox isnullSolution 2:
You can put something like the empty string into SelectedItemFromComboBox and modify your query:
SELECT*FROM Table1
WHERE SelectedItemFromComboBox =''OR Column1 = SelectedItemFromComboBox;
Solution 3:
SELECT*FROM Table1
WHERE Column1 = Column1
will get all the data
so you can use a null value
SELECT*FROM Table1
WHERE Column1 = isnull(some_value, Column1)
where some value is NULL. To do this use an empty string and then this
SELECT*FROM Table1
WHERE Column1 = isnull(CASEWHEN some_value =''thenNULLelse some_value end)), Column1)
and this will return what you want
Solution 4:
In this condition you can set the "SelectedItemFromComboBox" to 0 and update the query in this way so if first condition not match its going for OR condition where 0=0 and returns all records for initial combobox value.
SELECT * FROM Table1
WHERE Column1 = SelectedItemFromComboBox OR 0=SelectedItemFromComboBox ;
Solution 5:
If for some reason you are unable to modify the query and you only have control over the value going in, and you're not using parameterized queries, and you know 100% how to protect against SQL injection, then you can set SelectedItemFromComboBox to '' OR 1 = 1. This should be extremely rare and only be needed if there's bad code that you don't have control over, and is completely a hack.
Post a Comment for "Where That Selects All?"