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:
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?