Hi all!
I have a form with a combobox, a listbox and 2 command buttons.(see photo and neglect the blank listview)
I select items from the combobox and add items to my listbox after clicking the button.(no problem with this)
Then, I need to save each item of the ListView to my database. There can be more than one item in the Listbox,depending on how many were added by the user. I was thinking of a way to loop through the items and add each one, and stop adding when all have been saved to a database.
I tried this,
For x = 0 To ListBox1.Items.Count - 1
'For Each item As String In ListBox1.Items
cmd.Parameters.Clear()
sqlSaveAdd = "INSERT INTO lab_req ( @req_test)"
cmd.Parameters.AddWithValue("@req_test", ListBox1.Items)
cmd.CommandText = sqlSaveAdd
cmd.ExecuteNonQuery()
Next
Upon running this, it will say data is added but when I check the db, this is what I find "System.Windows.Forms.ListBox+ObjectCollection" saved there.
I also had triend looping with
For Each item As String In ListBox1.Items
'For Each item As String In ListBox1.Items
cmd.Parameters.Clear()
sqlSaveAdd = "INSERT INTO lab_req ( @req_test)"
cmd.Parameters.AddWithValue("@req_test", ListBox1.Items)
cmd.CommandText = sqlSaveAdd
cmd.ExecuteNonQuery()
Next
With the same result; "System.Windows.Forms.ListBox+ObjectCollection" is posted to the db instead of the items.
*I have ommited some codes (like connection settings, no problem with it, also some other items which are saved together with listiview items in other columns)
I will appreciate any help please.
Thanks and peace to you.