[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

multiple insert from list box  using ASP.NEt

Posted on 2006-03-22
1
Medium Priority
?
219 Views
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))
                cmd.Connection.Open()
                cmd.ExecuteNonQuery()
                cmd.Connection.Close()
            End If
        Next

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.

0
Comment
Question by:pratikshahse
1 Comment
 
LVL 14

Accepted Solution

by:
nayernaguib earned 500 total points
ID: 16258339
Replace ListBox1.SelectedItem.Text with ListBox1.Items(i-1).Text in the Insert statement.

_______________

  Nayer Naguib
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Progress
Loops Section Overview

865 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