I've an sql table. I've also a list in my Asp.Net code (C#).
public static List listColumns = new List();
And listColumns contains 1,2,3...10 randomly. For example it can contains 1, 5, 6, 9. I want to make a query with this conditions. So, If the list has these values, my query should be:
SELECT * FROM Table WHERE id=1 or id=5 or id=6 or id=9
The listColumns may contains different values and has different counts. How can I do this query regularly?
Linq-to-SQL:
Generated SQL:
EDIT
An approach that yields parameterized SQL (not that it's all that useful if the number of parameters keeps changing):
Here is a solution without a
for
loop, but unfortunately also without a parameterized SQL statement:Please note that using
select *
is considered as a bad practiceedit Here is some new code because your list is of type
System.Web.UI.MobileControls.List
edit 2 I have taken the code from your comment:
I guess that you have this on the dropdown changed event or something? and your dropdown has a string like "1,5,6,9" in the value. If all my assumptions are correct you can use:
pass query variable to sqlcommand