Page 1 of 1

VISUAL STUDIO 2008 DATABASE ERROR! NEED YOUR HELP ASAP!

Posted: Sun Feb 19, 2012 2:26 pm
by romanuel111
Hello Guys! I NEED YOUR HELP!!!?

I have a problem guys with regards to my project..
my problem is that I cannot Update or Delete the FIRST RECORD if I will not click or move the next button first or the navigation buttons..

BUT if I am going to UPDATE or DELETE the FIRST RECORD without moving or clicking the navigation buttons, I come up with this error:

>>>>>>>>>>>>>> "There is no row at position -1" <<<<<<<<<<


I have already a primary key in my table.. .I'm using MS Access.

It's almost 3 weeks of trying to find the solution for this problem...

what should I do guys??

here is the code if ever you want to see:

for UPDATE:

Dim cb As New OleDb.OleDbCommandBuilder(da)


ds.Tables("pok").Rows(inc).Item("Borrowe… = txtname.Text <<< The ERROR points in this part!
ds.Tables("pok").Rows(inc).Item("LastNam… = txtlast.Text
ds.Tables("pok").Rows(inc).Item("Address… = txtadd.Text
ds.Tables("pok").Rows(inc).Item("Contact… = txtcontact.Text

da.Update(ds, "pok")

MsgBox("Data updated")


for DELETE:

Dim cb As New OleDb.OleDbCommandBuilder(da)

If MessageBox.Show("Do you really want to Delete this Record?", _
"Delete", MessageBoxButtons.YesNo, _
MessageBoxIcon.Warning) = DialogResult.No Then


inc = 0
NavigateRecords()

MsgBox("Operation Cancelled!")
Exit Sub
End If



ds.Tables("pok").Rows(inc).Delete() <<< The ERROR points in this part!
MaxRows = MaxRows - 1
inc = 0
NavigateRecords()
da.Update(ds, "pok")

and SOMETIMES in this code:

Private Sub NavigateRecords()

txtname.Text = ds.Tables("pok").Rows(inc).Item(0) <<< The ERROR points in this part!
txtlast.Text = ds.Tables("pok").Rows(inc).Item(1)
txtadd.Text = ds.Tables("pok").Rows(inc).Item(2)

End Sub


One thing guys! If I am going to add records some of the fields of my database in empty and this made my project errors too..


my source or my guide of this code is: http://www.homeandlearn.co.uk/net/vbnet.html in the 13th part or chapter..



PLEASE GUYS I REALLY NEED YOUR HELP! THANKS VERY MUCH AND GOD BLESS!

Re: VISUAL STUDIO 2008 DATABASE ERROR! NEED YOUR HELP ASAP!

Posted: Sun Feb 19, 2012 5:30 pm
by CodenStuff
Im not familiar with database coding but from looking at your post and the error which says ">>>>>>>>>>>>>> "There is no row at position -1" <<<<<<<<<<" I think some variable in your code should not be allowed to go below 0 or 1

Try change the variable Inc to 1 at the start of your code or wherever its declared.

What is the code you have for the navigation buttons?

Re: VISUAL STUDIO 2008 DATABASE ERROR! NEED YOUR HELP ASAP!

Posted: Mon Feb 20, 2012 3:52 am
by romanuel111

Before the codes for my navigation. Sir, I am very thankful that you give attention to my question.. because our instructor did not discussed this topic to us he just gave us the site (which I posted with my question) that's why we almost going crazy to find the solution of the errors, for the site explanation itself is incomplete... God Bless You Sir! More Power to this site. Thanks very much!

________________________________________________________________
CODES FOR FIRST RECORD
Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfirst.Click

If inc <> 0 Then
inc = 0
NavigateRecords()
End If

End Sub

_____________________________________________________________________________

CODES FOR LAST RECORD
Private Sub btnlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlast.Click


If inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If

End Sub

__________________________________________________________________________


CODES TO MOVE NEXT RECORD

Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Records!")
End If

End Sub

_______________________________________________________________________________

CODES TO MOVE PREVIOUS RECORD

Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
ElseIf inc = -1 Then
MsgBox("No Records Yet")
ElseIf inc = 0 Then
MsgBox("First Record")
End If

End Sub

Re: VISUAL STUDIO 2008 DATABASE ERROR! NEED YOUR HELP ASAP!

Posted: Mon Feb 20, 2012 10:03 am
by clanc789
Please use the code tags to show codes.
Code: Select all
These tags

Re: VISUAL STUDIO 2008 DATABASE ERROR! NEED YOUR HELP ASAP!

Posted: Mon Feb 20, 2012 10:53 am
by romanuel111
clanc789 wrote:
Please use the code tags to show codes.
Code: Select all
These tags

what do you mean Sir? Thanks!

Re: VISUAL STUDIO 2008 DATABASE ERROR! NEED YOUR HELP ASAP!

Posted: Mon Feb 20, 2012 11:05 am
by clanc789
If you show your codes (e.g.):
Code: Select all
Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click
 If inc > 0 Then
 inc = inc - 1
 NavigateRecords()
ElseIf inc = -1 Then
 MsgBox("No Records Yet")
ElseIf inc = 0 Then
 MsgBox("First Record")
 End If

 End Sub

Re: VISUAL STUDIO 2008 DATABASE ERROR! NEED YOUR HELP ASAP!

Posted: Tue Feb 21, 2012 4:52 am
by CodenStuff
In your form load event try change this:
Code: Select all
inc = - 1
To this:
Code: Select all
inc = 0

Re: VISUAL STUDIO 2008 DATABASE ERROR! NEED YOUR HELP ASAP!

Posted: Sun Mar 11, 2012 3:29 pm
by romanuel111
thanks for the response guys, I really appreciate the effort but sadly I still have the same errors.. I am still working and looking for the solution.. cryer;

Godbless!