listbox and sql stored procedure

J

John

Hi,
First of all sorry for my not perfect english.

I've got listbox in my .aspx page where the users can make multiple
selection.
So, Users can select 7 items in listbox, I have to take value from
items and pass it to stored procedure to delete 7 rolls in my table. Thats
simple, but what if user select 3 or 30 items in listbox? The problem is
that I dont know the number of the parameters, and how to pass them. can I
use array or is there some different solution?

Of course I can take the collection of items and for every item, I can
call stored procedure, but this is no good in performance reason.
Please help me
 
J

Josh

write a routine to concatenate the selected IDs into a comma seperated
string then pass this as a single varchar parameter in the proc

create procedure pdTableName @IDs varchar(4000) AS

DELETE FROM TableName WHERE ID in (@IDs)


something like that anyway...
 
S

Scott G.

How about something like:

CREATE PROCEDURE pdTableName @IDs VARCHAR(4000)
AS
EXEC ('DELETE FROM TableName WHERE ID IN (' + @IDs + ')')
RETURN 0

Of course, you'd have to make sure that @IDs has all of the single quotes and commas, or you could add that to your stored procedure.

Scott
write a routine to concatenate the selected IDs into a comma seperated
string then pass this as a single varchar parameter in the proc

create procedure pdTableName @IDs varchar(4000) AS

DELETE FROM TableName WHERE ID in (@IDs)


something like that anyway...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top