3

A little outside my comfort zone...

Is there any way to pass multiple values (a list of values) to a query via ODBC Parameters in VB.Net?

For instance, is there a way to create a query along the lines of:

-- vb.net has something like Dim itemNumbers As New List(Of Integer)(SomeCount)

SELECT Cost, Description
FROM   MyItemList
WHERE  ItemNum IN (<my list of item numbers>)

Thanks!

Bala R
  • 107,317
  • 23
  • 199
  • 210
Wonko the Sane
  • 10,623
  • 8
  • 67
  • 92
  • [This answer](http://stackoverflow.com/questions/337704/parameterizing-a-sql-in-clause/337792#337792) seems to apply. Your question is very likely a duplicate of [Parameterizing a SQL IN clause?](http://stackoverflow.com/q/337704)... – Jorik Jun 08 '11 at 13:17

1 Answers1

1

Unfortunately ODBCParameter can hold only a single value. It might be easier to do something like this

cmd.CommandText = "SELECT Cost, Description FROM   MyItemList WHERE  ItemNum IN (@Items)"
cmd.Paramaters.AddWithValue("@Items", String.Join(", ", itemNumbers.Select(Function(i) i.ToString())))
Bala R
  • 107,317
  • 23
  • 199
  • 210
  • 1
    I would avoid this approach - it is open to SQL injection. This is a similar answer that deals with SQL injection: http://stackoverflow.com/a/337792/614523 – sennett Apr 16 '13 at 23:31