Q:

Pass multiple selected item id from list box to a stored procedure

I have a table-valued parameter like this
CREATE TYPE dbo.ss AS TABLE(ss1 integer);

My stored procedure looks like this:
ALTER PROCEDURE [dbo].[T_TransactionSummary] 
    @locations dbo.ss readonly
as
begin
    ...............
    .............
    AND (Location_tbl.Locid IN (@locations))

I have a listbox that contains multiple items. I can select multiple items from my listbox. How can I pass multiple Locationid to my stored procedure if I always select one location from my listbox?
I pass them like this (when selecting one item only):
dim locid as integer = Lstbox.selectedItem
cmd.parameters.add("@locations", locid)

but I don't know how to pass multiple selected items together from listbox to stored procedure. If I selected multiple items from my listbox I want to pass all item id together to my stored procedure  
I am working on vb.net windows forms..
sir in my case i am taking listbox selected item value like this:
 For i = 0 To cnt - 1
         Dim locationanme As String = LSTlocations.SelectedItems(i).ToString
       locid = RecordID("Locid", "Location_tbl", "LocName", locationanme)
   Next
        'End If

this locid i am passing to stored procedure..

A:

Try to use For each to get all selected items and then Using so that each time it loops the object is discarded after use, like:
For Each selectedItem As Object In ListBox1.SelectedItems
    Dim cmdText As String = "T_TransactionSummary"
    Dim locid As Integer = Int32.Parse(selectedItem.ToString())
    Using con As New SqlConnection("connection string here"), comm As New SqlCommand(cmdText), da As New SqlDataAdapter(comm)
            comm.CommandType = CommandType.StoredProcedure
            comm.Parameters.Add("@location", SqlDbType.Int).Value = locid
            comm.ExecuteNonQuery()
            Dim dst As New DataSet
            da.Fill(dst)
    End Using
Next

