Fisrt step: Get the items from listBox (VB):
(...)
Dim csv As New System.Text.StringBuilder()
Dim first As Boolean = True
For Each item As String In Me.ListBox1.SelectedItems
csv.Append(If(first, String.Empty, ",") + item)
first = False
Next
(...)
cmd.Parameters.AddWithValue("@paramName", csv.ToString())
(...)
This passes "item1,item2,arreloko" to the SP.
Add the following help function to your DB:
CREATE function [dbo].[fn_ParseCSVString]
(
@CSVString varchar(8000) ,
@Delimiter varchar(10)
)
returns @tbl table (s varchar(1000))
as
begin
declare @i int ,
@j int
select @i = 1
while @i <= len(@CSVString)
begin
select @j = charindex(@Delimiter, @CSVString, @i)
if @j = 0
begin
select @j = len(@CSVString) + 1
end
insert @tbl select substring(@CSVString, @i, @j - @i)
select @i = @j + len(@Delimiter)
end
return
end
Then use this in your query:
SELECT * FROM YourTable WHERE column1 IN (select*from dbo.fn_ParseCSVString(@paramName, ','))
SELECT * FROM YourTable t JOIN dbo.fn_ParseCSVString(@paramName, ',') csv on t.column1 = csv.s