0

I want to execute query

SELECT id, name FROM MyTable WHERE (id, name) IN ((1, 'One'), (2, 'Two'))

using OleDbConnection and OleDbCommand. Is it possible to pass the contents of IN clause as a parameter to command? If yes then what value should I pass a parameter value? List, IEnumerable or something else? If not then is it possible to pass the list of single values like for query

SELECT id, name FROM MyTable WHERE id IN (1, 2)
Demarsch
  • 1,419
  • 19
  • 39

2 Answers2

1

As long as I know you can't. I was trying something similar in the past and the only way I found was to create an stored procedure which receives a comma separated string and create the query dynamically, calling sp_execute at the end with the resulting string.

Oscar
  • 13,594
  • 8
  • 47
  • 75
0

Take a look at http://www.codeproject.com/Tips/231217/Parameters-SqlCommand-vs-OledbCommand-and-OdbcComm

You would be responsible for writing the SQL of course. SQL does not take anonymous objects for an IN parameter. You must specify what you are looking for in a single field.

Select * from table where field in (1,2,3) --Assuming field is an integer

For example.

TechneWare
  • 263
  • 1
  • 7