Delete from access

Snookie

Active member
Joined
Dec 13, 2010
Messages
29
Programming Experience
Beginner
Hey all

I have follow this guide.
Visual Basic .NET programming for Beginners - A Database Project

But then i want to delete from my access i get error
Here are a screenshot.
vb_error.png



Here are the code in my Deletebutton.
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
' If MessageBox.Show("Do you really want to Delete this Record?", _
' "Delete", MessageBoxButtons.YesNo, _
' MessageBoxIcon.Warning) = DialogResult.No Then
' MsgBox("Operation Cancelled")
' Exit Sub

'End If

Dim cb As New OleDb.OleDbCommandBuilder(da)

ds.Tables("AddressBook").Rows(inc).Delete()
MaxRows = MaxRows - 1

inc = 0
NavigateRecords()
da.Update(ds, "AddressBook")
End Sub

And if you see in the link, so i have write just what the guide says..
So i dont understandt how and why....

For me i thing its something the Navigator not get a message there tells what item are delete or something like that.
But i will be happy if some on could help me... or maybe give me some guide there are better and easy to follow...
 
As the error message says, you can't get data from a deleted row. You're deleting the row, then calling NavigateRecords and trying to display the row you just deleted. Why exactly are you doing anything between deleting and saving?
 
That guide says this:
We also reset the inc variable to zero, and call the NavigateRecords() subroutine. This will mean that the first record is displayed, after a record has been deleted.
It looks like they haven't taken into account the situation where you delete the first record, so there are no other records to display. You can adapt your NavigateRecords method to just clear the controls if there are no records to display. If you can't work out how to do that, just don;t worry about it for now and simply make sure that you don't ever delete the last record.
 
i am not sure there i do it. can you tell me where i shell put some code or delete some code in this guide... or what i shell do so its work for me. :)

it does not matter which item I delete then I get the same error.
whether it is the first middle or second last, so get the same error
 
Last edited:
jmc..You write this:
It looks like they haven't taken into account the situation where you delete the first record, so there are no other records to display. You can adapt your NavigateRecords method to just clear the controls if there are no records to display. If you can't work out how to do that, just don;t worry about it for now and simply make sure that you don't ever delete the last record.
Could you help me, so its works for me..
 
Back
Top