Possible Duplicate:
Parameterizing an SQL IN clause?
SQL how to get an equality comparator on a list of ints
I have a string in C# like this:
string listOfNumbers = "12,56,90,101"; //of course, this string could be different
and C# code
sqlCommand.Parameters.Add("@numbers", listOfNumbers);
SqlDataReader dataReader = sqlCommand.ExecuteReader();
But sqlCommand is binded to a stored procedure and inside is a sql statement like
SELECT * FROM TABLE1 WHERE COLUMN1 IN(@numbers)
@numbers
is NVARCHAR(30)
data type.
But when the breakpoint is at SqlDataReader dataReader = sqlCommand.ExecuteReader();
line then the VS2010 throws me an exception Incorrect syntax near my_stored_procedure
.
How to "convert" that string which contains numbers sepparated by comma in integers for IN operator ?
Maybe, the error is caused by SELECT * FROM TABLE1 WHERE IN("12,56,90,101")
and the error should be that could not convert from varchar to integer.