Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,220 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,165 people online right now. Registration is fast and FREE... Join Now!




Multiple selected value from list box into database

 
Reply to this topicStart new topic

Multiple selected value from list box into database, I have a win frm where i have 3 txt boxes and a list box, i have to st

rajathtc
6 Nov, 2007 - 09:23 PM
Post #1

New D.I.C Head
*

Joined: 6 Nov, 2007
Posts: 8


My Contributions
My code for insertion goes here please help. Can anybody tell what is wrong in this code only the first selected value is being inserted what can i do.

CODE

For i As Integer = 0 To lstParticipant.SelectedItems.Count - 1

              Try
        SQLstr = "INSERT INTO Training_Conducted (Date_of_Training, Training_Code,  Name_of_Facualty,      
                                                                           Participant_Name) VALUES
('" & DateTimePicker.Text & "','" & cmbTranCode.SelectedValue & "','" & txtFacInt.Text & ",'" & lstParticipant.SelectedItem(i).ToString & "')"
                        Command = New OleDbCommand(SQLstr, Mycn)
                        icount = Command.ExecuteNonQuery
                        MessageBox.Show("Records Stored Successfully")
                    Catch ex As Exception
                        MessageBox.Show("could not insert record")
                    End Try


help me

*Always use code blocks for your code ==> code.gif

This post has been edited by PsychoCoder: 6 Nov, 2007 - 09:47 PM
User is offlineProfile CardPM
+Quote Post

girasquid
RE: Multiple Selected Value From List Box Into Database
6 Nov, 2007 - 09:39 PM
Post #2

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,295



Thanked: 18 times
Dream Kudos: 725
My Contributions
How many items are selected?

Try adding a MessageBox.Show("Item Count: " & lstParticipant.SelectedItems.Count) just before your for loop, so that you can be sure there is more than 1 item being selected.
User is offlineProfile CardPM
+Quote Post

rajathtc
RE: Multiple Selected Value From List Box Into Database
6 Nov, 2007 - 10:38 PM
Post #3

New D.I.C Head
*

Joined: 6 Nov, 2007
Posts: 8


My Contributions
i'm getting the selected value
like if i select 2 items count will be 2
if i select 4 items count will be 4

but in the participant column it is inserting System.Data.DataRowView insted of the value from the selected list
User is offlineProfile CardPM
+Quote Post

girasquid
RE: Multiple Selected Value From List Box Into Database
6 Nov, 2007 - 10:43 PM
Post #4

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,295



Thanked: 18 times
Dream Kudos: 725
My Contributions
Try using 1stParticipant.SelectedItem(i).Value.ToString(), and tell me what happens in that case.
User is offlineProfile CardPM
+Quote Post

rajathtc
RE: Multiple Selected Value From List Box Into Database
6 Nov, 2007 - 11:03 PM
Post #5

New D.I.C Head
*

Joined: 6 Nov, 2007
Posts: 8


My Contributions
if it is "selecteditems(i).tostring" i'm getting the previous error

if it is "SelectedItem(i).ToString then the first value is inserted and i'm getting the exception like column1 not found for the second value

if it is "SeletedItem(i).Value.ToString then the exception is Public member 'Value' on type 'DataRowView' not found.
User is offlineProfile CardPM
+Quote Post

girasquid
RE: Multiple Selected Value From List Box Into Database
6 Nov, 2007 - 11:11 PM
Post #6

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,295



Thanked: 18 times
Dream Kudos: 725
My Contributions
Try selectedValue(i).ToString.
User is offlineProfile CardPM
+Quote Post

rajathtc
RE: Multiple Selected Value From List Box Into Database
6 Nov, 2007 - 11:16 PM
Post #7

New D.I.C Head
*

Joined: 6 Nov, 2007
Posts: 8


My Contributions
if i do that it strores vlues dividing the string into character
ie.,

if the name inside lst box is RAJATH
and the count is 4 it will store
R
A
J
A
in different rows
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:42AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month