Okay I have put way too much time into what should have been a simple bit of coding, I can not figure out why this doesn't work. I am trying to create a save file for my program and for the most part it works but the one thing I can't save into a txt is the multi-column listview. Instead, i created a table in the database that gets wiped, and then rewritten with the new data when the user saves. However, for some reason, I am getting the error that's in the title.
My connection string:
Public strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
System.Environment.CurrentDirectory & "\OmegaTestDatabase.mdb"
Save Code:
Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
Dim DbConnection As New OleDbConnection(strConnectionString)
Dim SqlQry As New OleDbCommand("INSERT INTO Inventory VALUES (@ItemName, @ItemQuality, @SellPrice)", DbConnection)
Dim DeleteCmd As New OleDbCommand("DELETE FROM Inventory WHERE [Sell Price] >= 0", DbConnection)
DbConnection.Open()
DeleteCmd.CommandType = CommandType.Text
DeleteCmd.Connection = DbConnection
DeleteCmd.ExecuteNonQuery()
DeleteCmd.Dispose()
DbConnection.Close()
DbConnection.Open()
For Each item As ListViewItem In ItemBagList.Items
SqlQry.Parameters.AddWithValue("@ItemName", item.SubItems(0))
SqlQry.Parameters.AddWithValue("@ItemQuality", item.SubItems(1))
SqlQry.Parameters.AddWithValue("@SellPrice", item.SubItems(2))
SqlQry.ExecuteNonQuery()
Next
DbConnection.Close()
Dim sfd As New SaveFileDialog
sfd.Filter = "Text Files *.txt|*.txt"
sfd.Title = "Save File"
sfd.ShowDialog()
Dim myPath As String = sfd.FileName
' To save
FileOpen(1, myPath, OpenMode.Output)
PrintLine(1, PlaySTR.Value)
PrintLine(1, PlayLUC.Value)
PrintLine(1, PlayAGI.Value)
PrintLine(1, PlayINT.Value)
PrintLine(1, PlaySpirit.Value)
PrintLine(1, PlayLife.Value)
PrintLine(1, PlayHP.Value)
PrintLine(1, PlaySP.Value)
PrintLine(1, PlayMDEF.Value)
PrintLine(1, PlayPDEF.Value)
PrintLine(1, PlayRDEF.Value)
PrintLine(1, PlayMATK.Value)
PrintLine(1, PlayPATK.Value)
PrintLine(1, PlayRATK.Value)
PrintLine(1, WpnMinDmg.Value)
PrintLine(1, WpnMaxDmg.Value)
PrintLine(1, PlaySkillDmg.Value)
PrintLine(1, PlayMAcc.Value)
PrintLine(1, PlayPAcc.Value)
PrintLine(1, PlayRAcc.Value)
PrintLine(1, PlayCritChance.Value)
PrintLine(1, PlayCritMult.Value)
PrintLine(1, BlockValue.Value)
PrintLine(1, PlayDodge.Value)
PrintLine(1, PetSTR.Value)
PrintLine(1, PetLUC.Value)
PrintLine(1, PetAGI.Value)
PrintLine(1, PetINT.Value)
PrintLine(1, PetSpirit.Value)
PrintLine(1, PetLife.Value)
PrintLine(1, PetHP.Value)
PrintLine(1, PetSP.Value)
PrintLine(1, PetMDEF.Value)
PrintLine(1, PetPDEF.Value)
PrintLine(1, PetRDEF.Value)
PrintLine(1, PetMATK.Value)
PrintLine(1, PetPATK.Value)
PrintLine(1, PetRATK.Value)
PrintLine(1, PetMAcc.Value)
PrintLine(1, PetPAcc.Value)
PrintLine(1, PetRAcc.Value)
PrintLine(1, PetCritChance.Value)
PrintLine(1, PetCritMult.Value)
PrintLine(1, PetDodge.Value)
PrintLine(1, PetSkillDmg.Value)
PrintLine(1, MobHP.Value)
PrintLine(1, MobSP.Value)
PrintLine(1, MobMDEF.Value)
PrintLine(1, MobPDEF.Value)
PrintLine(1, MobRDEF.Value)
PrintLine(1, MobMATK.Value)
PrintLine(1, MobPATK.Value)
PrintLine(1, MobRATK.Value)
PrintLine(1, MobMAcc.Value)
PrintLine(1, MobPAcc.Value)
PrintLine(1, MobRAcc.Value)
PrintLine(1, MobCritChance.Value)
PrintLine(1, MobCritMult.Value)
PrintLine(1, MobDodge.Value)
PrintLine(1, RaceCbo.SelectedItem)
PrintLine(1, PlaySkillCheck.Checked)
PrintLine(1, PetSkillCheck.Checked)
PrintLine(1, MobSkillCheck.Checked)
PrintLine(1, PetType.SelectedItem)
PrintLine(1, PlaySkillLvl.Value)
PrintLine(1, PetSkillLvl.Value)
PrintLine(1, PetLevelNum.Value)
PrintLine(1, MobCbo.SelectedItem)
PrintLine(1, GoldValue.Value)
PrintLine(1, SilverValue.Value)
PrintLine(1, CopperValue.Value)
PrintLine(1, SkillBar1.SelectedItem)
PrintLine(1, SkillBar2.SelectedItem)
PrintLine(1, SkillBar3.SelectedItem)
PrintLine(1, SkillBar4.SelectedItem)
PrintLine(1, SkillBar5.SelectedItem)
PrintLine(1, SkillBar6.SelectedItem)
PrintLine(1, SkillBar7.SelectedItem)
PrintLine(1, SkillBar8.SelectedItem)
PrintLine(1, SkillBar9.SelectedItem)
PrintLine(1, SkillBar10.SelectedItem)
PrintLine(1, SkillLvl1.Value)
PrintLine(1, SkillLvl2.Value)
PrintLine(1, SkillLvl3.Value)
PrintLine(1, SkillLvl4.Value)
PrintLine(1, SkillLvl5.Value)
PrintLine(1, SkillLvl6.Value)
PrintLine(1, SkillLvl7.Value)
PrintLine(1, SkillLvl8.Value)
PrintLine(1, SkillLvl9.Value)
PrintLine(1, SkillLvl10.Value)
'saves the values of each of the above controls into a txt file with one line per value
FileClose(1)
End Sub
I'm at a complete loss, someone please help me?
EDIT: The table and the listview both have 3 columns titled Item Name, Item Quality, and Sell Price. I have attempted to change the Sell Price column in the database from number, to Short Text, and back to Number and that didn't help, so the problem isn't with datatype.
The problem occurs during the first iteration of For Each... Next