0

Is there a way to pass a list into a SqlCommand so it doesn’t try to convert the string to int? IE:

I can do this:

SqlCommand command = new SqlCommand("SELECT  * FROM  modules WHERE (moduleID IN (2,3,4))", connection);

But this tries to convert it and breaks

SqlCommand command = new SqlCommand("SELECT  * FROM  modules WHERE (moduleID IN (@modulelist))", connection);
command.Parameters.AddWithValue("@modulelist", "2,3,4");
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
CerIs
  • 527
  • 3
  • 6
  • 14
  • 2
    You pass a **single** string which is not working. Use seperate values – juergen d Jun 23 '14 at 15:35
  • You did try to google the exact words in your question right? And you did come upon this answer: http://stackoverflow.com/questions/2377506/pass-array-parameter-in-sqlcommand right? – Tallmaris Jun 23 '14 at 15:37
  • 1
    Not sure I like the duplicate - a stored procedure with a TVP might be a better approach here than looping through a bunch of values one at a time. http://stackoverflow.com/questions/11102358/how-to-pass-an-array-into-a-sql-server-stored-procedure – Aaron Bertrand Jun 23 '14 at 15:43

0 Answers0