Connection.Open()
Dim cmd As New OleDbCommand
cmd.CommandText = "INSERT INTO PANELDETAIL
(PanelID,PanelName,ExamName) VALUES (@PanelID,@PanelName,@ExamName)"
cmd.Parameters.AddWithValue("@PanelID", tboxID.Text)
cmd.Parameters.AddWithValue("@PanelName", tboxName.Text)
cmd.Parameters.AddWithValue("@ExamName", lviewIncluded.Text)
cmd.Connection = Connection
cmd.ExecuteNonQuery()
Connection.Close()
Basically, this code just inserted a certain record on my
database...All seems fine but the one with the question mark, I don't
know how to insert but I am certain that it's wrong.I just want to ask
how can I inserted all the items in a listview(lviewIncluded) in my
database thanks in advance...

Saving ListViewItemCollection
Tkanos
Andrew Todd
Try this
dim currentItem As String
Connection.Open()
For Each currentItem In lviewIncluded.Items
Dim cmd As New OleDbCommand
cmd.CommandText = "INSERT INTO PANELDETAIL (PanelID,PanelCode,ExamName) VALUES (@PanelID,@PanelCode,@ExamName)"
cmd.Parameters.AddWithValue("@PanelID", tboxDummy.Text)
cmd.Parameters.AddWithValue("@PanelCode", tboxCode.Text)
cmd.Parameters.AddWithValue("@ExamName", currentItem)
cmd.Connection = Connection
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
Next
Connection.Close()
Menachem_P
Hmm, I dont understand how it can be possible, take for example, my solution above. It should go for each item in the listview, unless each item is the same
What values are you getting in the foreach loop
Which value is the same as the last value
Dick Campbell
Conversion from type 'ListViewItem' to type 'String' is not valid. pointing to the line
For Each currentItem In lviewIncluded.Items
Notice also that I am using this code for the Update statement and not an insert one, so if that is an issue then perhaps there some changes to be made..thanks.
Paul Diston
sajohnstone
For Each *ListViewItem In lviewIncluded
Dim cmd As New OleDbCommand
cmd.CommandText = "INSERT INTO PANELDETAIL (PanelID,PanelCode,ExamName) VALUES (@PanelID,@PanelCode,@ExamName)"
cmd.Parameters.AddWithValue("@PanelID", tboxDummy.Text)
cmd.Parameters.AddWithValue("@PanelCode", tboxCode.Text)
cmd.Parameters.AddWithValue("@ExamName", lviewIncluded.Text)
cmd.Connection = Connection
cmd.ExecuteNonQuery()
Next
Connection.Close()
*ListViewItem is a type and cannot be used as an expression
this was the debug error i am getting after your suggestion.I know there's a little mistake here on my part, but I beg your pardon as I am new here in programming...thanks.
GS80
CESAR DE LA TORRE
interesting.
I've never worked with listview just yet so I am just guessing from the top of my head.
What items are stored in the ListViewItem
how about this:
dim counter as int
dim currentItemValue as string
for counter = 0 to me.listItem.Count
'Your SQL statements here
currentItemValue = me.listItem[counter].Text
next counter
Aquineas
anf600
I hope this helps...
since there will be a collection of items in the listview, you cannot insert the entire list for 1 record like this.
Remember in SQL, 1 row = 1 record
From the code shown, to me, it seems as if you want to insert the text value of the control lviewIncluded.Text. is this correct
If so, then it should be fine. Are you getting any errors if so - where and what is the error
You are appearing to be asking how to insert all the items in the listview in SQL.
you would insert an entry per item in listview. for example, here is a pseudocode:
open connection
foreach item in lviewIncluded
Create SQL Insert command.
Add current item in Insert Statement
Execute query
Clear parameters
end foreach
close connection.
I hope this gives you a starting point.