sql server - How to send multiple parameters hyphen separated in to a stored procedure as a List<string>? -


i have received multiple values hyphen saparated text box eg. "one-two-three-four", first want store hyphen saparated values , send list stored procedure parameters.

if want send single paramter :

use below function split string in db

create function splitstring (       @input nvarchar(max),   @character char(1) ) returns @output table (   item nvarchar(1000) ) begin   declare @startindex int, @endindex int    set @startindex = 1   if substring(@input, len(@input) - 1, len(@input)) <> @character   begin         set @input = @input + @character   end    while charindex(@character, @input) > 0   begin         set @endindex = charindex(@character, @input)          insert @output(item)         select substring(@input, @startindex, @endindex - 1)          set @input = substring(@input, @endindex + 1, len(@input))   end    return end go 

use in sp

select item dbo.splitstring('one-two-three-four', '-') 

edit :

if want send table-valued parameter :

in c#:

string [] list = textbox.text.split('-'); datatable dt = new datatable(); dt.columns.add("column1"); foeach(string s in list) { dt.rows.add(s); } 

pass sp :

sqlparameter parameter = new sqlparameter();  //the parameter sp must of sqldbtype.structured  parameter.parametername="@sample";  parameter.sqldbtype = system.data.sqldbtype.structured;  parameter.value = dt;  command.parameters.add(parameter);  

Comments