listbox and sql stored procedure

Discussion in 'ASP .Net Web Controls' started by John, Jun 30, 2004.

  1. John

    John Guest

    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
    John, Jun 30, 2004
    #1
    1. Advertising

  2. John

    Josh Guest

    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...
    Josh, Jun 30, 2004
    #2
    1. Advertising

  3. John

    Scott G. Guest

    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
    "Josh" <> wrote in message news:...
    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...
    Scott G., Jun 30, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    2
    Views:
    493
    =?Utf-8?B?RGVlcA==?=
    Jul 9, 2004
  2. =?Utf-8?B?VGltOjouLg==?=

    Stored Procedure and SQL String????

    =?Utf-8?B?VGltOjouLg==?=, Mar 1, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    2,485
    =?Utf-8?B?VGltOjouLg==?=
    Mar 1, 2005
  3. Mike P
    Replies:
    0
    Views:
    3,276
    Mike P
    Jun 19, 2006
  4. John

    listbox and sql stored procedure

    John, Jun 30, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    132
    DalePres
    Jul 2, 2004
  5. John

    listbox and sql stored procedure

    John, Jun 30, 2004, in forum: ASP .Net Security
    Replies:
    0
    Views:
    112
Loading...

Share This Page