---
title: "`WHERE … IN @xs`, where @xs parameter is a value list: Supported by ADO.NET?"  
description: "`WHERE … IN @xs`, where @xs parameter is a value list: Supported by ADO.NET?"  
author: "Anonymous User"  
published: 2013-06-19  
updated: 2013-06-19  
canonical: https://www.mindstick.com/forum/1207/where-in-xs-where-xs-parameter-is-a-value-list-supported-by-ado-dot-net  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# `WHERE … IN @xs`, where @xs parameter is a value list: Supported by ADO.NET?

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs), \
\
I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to create a parameterised [ADO.NET](https://www.mindstick.com/articles/804/connection-pooling-in-ado-dot-net) query with a WHERE … IN @xs clause, where @xs is a short list of possibly non-contiguous values, for [instance](https://www.mindstick.com/forum/155658/testing-connection-to-cloud-sql-instance-with-a-mysql-client-from-vm-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](https://www.mindstick.com/forum/158623/what-is-an-argumentexception-and-when-might-it-be-thrown-in-an-asp-dot-net-mvc-project) due to `values`\
\
Neither the System.Data.SqlDbType enum nor the types in the System.Data.SqlTypes [namespace](https://www.mindstick.com/articles/12552/namespace) suggest that this [scenario](https://yourviews.mindstick.com/view/81221/sports-will-change-the-education-scenario) is supported. Must I revert to [dynamic SQL](https://www.mindstick.com/interview/623/what-is-dynamic-sql) (i.e. manually composing the final SQL CommandText using string [operations](https://www.mindstick.com/blog/304985/how-does-devops-bridge-the-gap-between-development-and-operations-teams-like-git))?\
\
Any help on above is really appreciated.

## Replies

### Reply by Anonymous User

Hi Garry,\
You will have to build the parameters one at a time:\
int[] xs = { 2, 3, 5, 8, 13 };var c = new SqlCommand();var parameters = xs.Select((x, i) => string.Concat("@xs", i)).ToList();for (var i = 0; i < xs.Count; i++){ c.Parameters.AddWithValue(parameters[i], xs[i]);}\
c.CommandText = string.Format( "SELECT ... FROM ... WHERE ... IN ({0})", string.Join(", ", parameters)); \
Thanks in advance.


---

Original Source: https://www.mindstick.com/forum/1207/where-in-xs-where-xs-parameter-is-a-value-list-supported-by-ado-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
