I am having a problem getting this code to work in deleting records from a database. The path to the database is correct and I have another couple of event handlers that work fine using this same datbase so I know that the path to the Db is good. Any advice would be great, thanks. I marked where the error occurs at debugging. I know what line breaks the program, but I don't know why.
Private Sub radRemoveWords_Click(sender As System.Object, e As System.EventArgs) Handles radRemoveWords.Click
Dim _intUpperBound As Integer = 1000 'dummy value
Dim str_newWords(_intUpperBound) As String
' make the database connection to update the table
Dim frmSpellingTest As New frmSpellingTest
Dim _strFileLocation2 As String = frmSpellingTest._strFileLocation
Dim _intUpperBound2 As Integer = frmSpellingTest._intUpperBound
Try
' Array to use in handling incoming data from Db
Dim strWords(_intUpperBound2) As String ' frmSpellingTest._intUpperBound
' SQL string to grab spelling words from the database table (argument 1 to data adapter creation)
Dim strSQL As String = "SELECT * FROM spelling_list"
' User can supply location of word list (default will be displayed for ease of use)
' Path to the database table (argument 2 to data adapter creation)
Dim location As String = _strFileLocation2
Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;" & "Data Source=" & location
' Use the SQL statement and path to create a data adapter to database
Dim odaSpellingList2 As New OleDb.OleDbDataAdapter(strSQL, strPath)
' Create an DataTable to hold the data retrieved
Dim datWords As New DataTable
' Counter to use in filling the ListBox object
Dim intCount As Integer = 0
' Fill the DataTable with the data in the DataAdapter
odaSpellingList2.Fill(datWords)
' command builder will build a SQL command to use
Dim cb2 As New OleDb.OleDbCommandBuilder(odaSpellingList2)
' this is the dataset to work with to update the database with
Dim spelling2 As New spelling_listDataSet
' this is how many items are in the listbox object
Dim size As Integer = lstEditWords.Items.Count
Dim X As Integer = 0
For X = 1 To size ' from 0 to however many spelling words there are
If (lstEditWords.GetItemChecked(X - 1)) Then
spelling2.Tables("spelling_list").Rows(X).Delete() 'ERROR IS HERE
' BUT WHY?
odaSpellingList2.Update(spelling2, "spelling_list")
lstEditWords.Items.RemoveAt(X)
End If
Next
' close the Db connection now
odaSpellingList2.Dispose()
Catch exception As SystemException
MsgBox("File Not Found", 16, "Missing Spelling List File")
Me.Close()
End Try
End Sub