Question

i have checkbox list to select multiple value ,now i want to pass this multiple selected value to my stored procedure using one parameter

insert into tblAccessRights (roleid,customerid,SubcustomerId)
values(@_roleid,@CustomerId,@SubcustomerId,)

in above query @SubcustomerId is parameter which will hold the multiple selected value from checkboxlist so,now the entry should be like as follow

roleid customerid subcustomerid
 1        2           6
 1        2           7
 1        2           8

this subcustomerid is multiple selected value from check box ,how can i achieve this with one parameter,if any other way to do this then please reply

Can it be done with dynamic query if i take checkboxlist value as comma separated string and accordingly pass it to dynamic insert query...

Was it helpful?

Solution

i got solution for this finally,!!!! im giving my solution for refrence

i took the check box list in string as comma separated value and pass it to stored procedure then i use dynamic query to insert this value as follow:

 
create table tblrmp
 ( id int identity (1,1),
 name varchar(20), 
subcat varchar(20) ) 

declare @S varchar(20) set @S = '1,2,3,4,5' declare @sql varchar(max) while len(@S) > 0 begin print left(@S, charindex(',', @S+',')-1) set @sql='insert into tblrmp values(''abc'','+left(@S, charindex(',', @S+',')-1)+')' exec(@sql) set @S = stuff(@S, 1, charindex(',', @S+','), '') end

output: id name subcat 1 abc 1 2 abc 2 3 abc 3 4 abc 4 5 abc 5

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top