title: How to create a SQL query in vb.net with 'select ...from ..where id in (list)' syntax
body: <p>at the first glance my problem looks simple, still I can't tackle it.
  I have to do some corrections to an ASP.NET program a document mangement system, with its backendcode written in vb. 
  The user in my specific case can choose several documents from a list, which can then be processed on a different webpage. So the ids of those documents are put into a sessionvariable and on the new page a query concerning only those ids is done. The implementation is quite horrid:</p>
  
  <pre><code> For Each Doks As String In Session.Item("choosenDocuments")
     strSQL = "SELECT [...] FROM Dokument where DokumentID = " &amp; Doks
     cmd = New SqlCommand(strSQL, conDatabase)
     dr = cmd.ExecuteReader
     dr.Read()
     [...]
     dr.Close()
   Next
  </code></pre>
  
  <p>I thought of using a parameterized statement, to create something like:</p>
  
  <pre><code>SELECT * FROM DOCUMENT WHERE DokumentID in (5,78,456)
  </code></pre>
  
  <p>But I fail to see, how to achive this programatically.
  Is is what i came up with so far:</p>
  
  <pre><code>Private Sub display(ByVal argument As IEnumerable(Of Integer))
    Try
      Dim result As New DataTable()
        Using con As SqlConnection = getCon() 
          Dim querystring As String = "select * from Dokuments where " &amp;
              "GPDokumenteID in @id"
            Using command As New SqlCommand(querystring, con)
              command.Parameters.Add("@id", SqlDbType.Structured)
              command.Parameters("@id").Value = argument
              Using adapter As New SqlDataAdapter
                adapter.SelectCommand = command
                adapter.Fill(result)
              End Using
            End Using
         End Using
         For Each dr As DataRow In result.Rows
           Console.WriteLine(dr(0).ToString() &amp; "  " &amp; dr(1).ToString())
         Next
      Catch ex As Exception
          Console.WriteLine("BOOM: " &amp; ex.Message)
      End Try
  End Sub
  </code></pre>
  
  <p>This code fails at runtime, complaining that integer arrays cant be cast in IEnumerable.</p>
  
  <p>I have found some sources like <a href="https://stackoverflow.com/questions/11102358/how-to-pass-an-array-into-a-sql-server-stored-procedure">this</a> or <a href="http://msdn.microsoft.com/de-de/library/bb675163%28v=vs.110%29.aspx" rel="nofollow noreferrer">this</a> but I still fail to construct a simple query example from that. Is my thinking to simple? Since there is such an elegant way to fill a SQL Query from a list I thought there would be a way to use this programatically.</p>
  
  <p>Kind regards</p>
  
  <p>Lorgarn</p>