Click here to Skip to main content
15,886,701 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a save method for the program I have just about finished, and most of the values that need to be to be saved were straightforward and could be saved in a txt. The exception is the ItemBagList listview. Every method I have tried has come to the same thing, I need to store one or more items from the listview in a variable or array.

The simplest method I have found is to store the items in a database table, the program would store the data in the db table at the same time it saves everything else to a txt, then when it opens the txt it will also repopulate the listview from the db table.

Here is my code currently:

VB
Dim DbConnection As New OleDbConnection(strConnectionString)
Dim SqlQry As New OleDbCommand("INSERT INTO Inventory ([Item Name], [Item Quality], [Sell Price]) VALUES @ItemName, @ItemQuality, @SellPrice", DbConnection)
Dim DeleteCmd As New OleDbCommand("DELETE * FROM Inventory", DbConnection)
Dim ItemName As String
Dim ItemPrice As Integer
Dim ItemQuality As String

DbConnection.Open()

DeleteCmd.CommandType = CommandType.Text

DeleteCmd.Connection = DbConnection

DeleteCmd.ExecuteNonQuery()

DbConnection.Close()

SqlQry.Parameters.AddWithValue("@ItemName", ItemName)
SqlQry.Parameters.AddWithValue("@ItemQuality", ItemQuality)
SqlQry.Parameters.AddWithValue("@SellPrice", ItemPrice)

For Each item In ItemBagList.Items

Next


The listview has 3 columns: Item Name, Item Quality, and Sell Price. What I need is to set a the appropriate variable to be equal to the appropriate column and to insert them into the Inventory table. Can anybody help me?
Posted

1 solution

VB
For Each lvi  As ListViewItem In ItemBagList.Items
' Create your command here and pass lvi.SubItems(0),lvi.SubItems(1) and lvi.SubItems(2)
' as the parameters
' For example SqlQry.Parameters.AddWithValue("@ItemName", lvi.SubItems(0))
Next
 
Share this answer
 
v2
Comments
KitsunePhoenix 19-Jun-15 10:02am    
Thank you, this advanced to my next problem :P

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900