forum

Home / DeveloperSection / Forums / `WHERE … IN @xs`, where @xs parameter is a value list: Supported by ADO.NET?

`WHERE … IN @xs`, where @xs parameter is a value list: Supported by ADO.NET?

Anonymous User229019-Jun-2013
Hi Developers,

I am trying to create a parameterised ADO.NET query with a WHERE … IN @xs clause, where @xs is a short list of possibly non-contiguous values, for instance (2, 3, 5, 8, 13). Can this be done? If so, how?

This won't work:

int[] xs = { 2, 3, 5, 8, 13 };  // I've also tried using a List<int> instead
var c = new System.Data.SqlClient.SqlCommand();
c.CommandText = "SELECT … FROM … WHERE … IN @xs";
c.Parameters.AddWithValue("@xs", xs);
  // throws ArgumentException due to `values`

Neither the System.Data.SqlDbType enum nor the types in the System.Data.SqlTypes namespace suggest that this scenario is supported. Must I revert to dynamic SQL (i.e. manually composing the final SQL CommandText using string operations)?

Any help on above is really appreciated.

Updated on 19-Jun-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By