G
Guest
The code for my 'delete record' button is:
Dim dc As New OleDbConnection
Dim dbLocation As String = "E:\NITLC\VB.NET\VideoClub\VideoClub.mdb"
dc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
dbLocation
Dim daCategorySelectText As String = "SELECT * FROM tblCategories"
Dim daCategory As OleDbDataAdapter = New
OleDbDataAdapter(daCategorySelectText, dc.ConnectionString)
Dim ds As New DataSet
Dim ButtonSubject, strItem, strDeletePrompt, strDeleteTitle As String
Dim result As DialogResult
strDeleteTitle = "Delete a "
strDeletePrompt = "You are about to delete the "
dc.Open()
daCategory.FillSchema(ds, SchemaType.Source, "tblCategories")
daCategory.Fill(ds, "tblCategories")
ButtonSubject = "Category"
strItem = ListBox1.GetItemText(ListBox1.SelectedItem)
Dim cmdBuilder As New OleDbCommandBuilder(daCategory)
ds.Tables("tblCategories").Rows(ListBox1.SelectedIndex).Delete()
strDeleteTitle += ButtonSubject
strDeletePrompt += ButtonSubject + " '" + strItem + "'." + Chr(13) + Chr(10)
strDeletePrompt += "Are you sure you want to delete it?"
result = MessageBox.Show(strDeletePrompt, strDeleteTitle,
MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
ds.Tables("tblCategories").AcceptChanges()
daCategory.Update(ds, "tblCategories")
Else
ds.Tables("tblCategories").RejectChanges()
End If
ListBox1.DataSource = ds.Tables("tblCategories")
dc.Close()
I've written similar code for add and edit operations, and those DO update
the database. The above code SEEMS to work - the highlighted entry disappears
- but when I browse the database in Access 2003, or exit from the app and run
it again, the deleted record is still there!
What am I missing?
Dim dc As New OleDbConnection
Dim dbLocation As String = "E:\NITLC\VB.NET\VideoClub\VideoClub.mdb"
dc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
dbLocation
Dim daCategorySelectText As String = "SELECT * FROM tblCategories"
Dim daCategory As OleDbDataAdapter = New
OleDbDataAdapter(daCategorySelectText, dc.ConnectionString)
Dim ds As New DataSet
Dim ButtonSubject, strItem, strDeletePrompt, strDeleteTitle As String
Dim result As DialogResult
strDeleteTitle = "Delete a "
strDeletePrompt = "You are about to delete the "
dc.Open()
daCategory.FillSchema(ds, SchemaType.Source, "tblCategories")
daCategory.Fill(ds, "tblCategories")
ButtonSubject = "Category"
strItem = ListBox1.GetItemText(ListBox1.SelectedItem)
Dim cmdBuilder As New OleDbCommandBuilder(daCategory)
ds.Tables("tblCategories").Rows(ListBox1.SelectedIndex).Delete()
strDeleteTitle += ButtonSubject
strDeletePrompt += ButtonSubject + " '" + strItem + "'." + Chr(13) + Chr(10)
strDeletePrompt += "Are you sure you want to delete it?"
result = MessageBox.Show(strDeletePrompt, strDeleteTitle,
MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
ds.Tables("tblCategories").AcceptChanges()
daCategory.Update(ds, "tblCategories")
Else
ds.Tables("tblCategories").RejectChanges()
End If
ListBox1.DataSource = ds.Tables("tblCategories")
dc.Close()
I've written similar code for add and edit operations, and those DO update
the database. The above code SEEMS to work - the highlighted entry disappears
- but when I browse the database in Access 2003, or exit from the app and run
it again, the deleted record is still there!
What am I missing?