I have an adapter in c# and I want to know if a value (type of int) is in a list of values. How can I do it? when I do send IN @sendList
it's giving me an error. I tried to use LIKE
like this @sendList LIKE '%'+ send +'%'
but Adapter can't convert from int to varchar...
Asked
Active
Viewed 63 times
0
-
1Please specify the error and add some code that explain how you tried to fetch this query. – HuBeZa Feb 06 '11 at 10:59
-
1The `IN` clause requires your values to be 1. comma separated and 2. enclosed in parentheses like so `IN (1,4,6,9)` – bitxwise Feb 06 '11 at 11:03
-
but can't i get the list as parameter? @HuBeZa, i wrote how i tried to fetch. the error is that it can't do @sendList LIKE '%'+ send +'%' becuse "send" is an int – aharon Feb 06 '11 at 11:15
-
1@sharon You cannot. you need to build the in clause yourself. http://stackoverflow.com/questions/337704/parameterizing-a-sql-in-clause has many suggestions. – nos Feb 06 '11 at 11:33
1 Answers
0
The easiest way would be splitting your list of IDs:
...
string.Format("Send IN {0}", string.Join(sendList.Select(id => id.ToString()));
But if you insist on a parameter, you can write an SQL function that convert your list to string. You can find many examples (like this) over the web.

HuBeZa
- 4,715
- 3
- 36
- 58
-
you can still use parameters, you just need to build an in clause with as many `?` as elements in your list - `in (?,?,?,?,?)` and loop through the list and assign parameters – nos Feb 06 '11 at 11:41