multiple insert from list box  using ASP.NEt

Posted on 2006-03-22
Last Modified: 2012-06-27
I have a form in which I am using a list box control. I select multiple items from the list box and then I want to insert all those items selected in a table.  I am using the following code to do that (which does not work)

 For i = 1 To ListBox1.Items.Count
            If ListBox1.Items(i - 1).Selected = True Then
                'strsub = ListBox1.SelectedItem.Text
                Dim cmd As New OleDbCommand("INSERT INTO table1 (promo_sub_brand)VALUES('" & ListBox1.SelectedItem.Text & "')", New OleDbConnection(conn))
            End If

it only takes the first item thats selected and then exits. what do I need to do in order to insert multiple items from a list box.

Question by:pratikshahse
    1 Comment
    LVL 14

    Accepted Solution

    Replace ListBox1.SelectedItem.Text with ListBox1.Items(i-1).Text in the Insert statement.


      Nayer Naguib

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    Exchange and Third Party application. 8 45
    squareUp  challenge 22 80
    wordsWithoutList  challenge 24 58
    pairs challenge 5 28
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now