problem with next record

saidev

Active member
Joined
Dec 22, 2005
Messages
27
Programming Experience
1-3
Hi,
is there any thing wrong with this code..? when i click next 2 times it blows out with error " there is no row at position 2" can you help me what is wrong with this..?
THanks,
If objDS.Tables(0).Rows.Count > Session("CurrentIndex") Then
Session("CurrentIndex") = Session("CurrentIndex") + 1
End If
objDataRow = objDS.Tables(0).Rows(Session("CurrentIndex"))
 
It might be just me (it's late here), but I don't think you have provided the necessary code logic to explain what goes wrong and where it does so for us to help you yet...
 
When it is equal to...

When the current index is equal to the row count your if statement is triggered and the index becomes greater than the count.

Try:
If objDS.Tables(0).Rows.Count >= Session("CurrentIndex") Then
 
Remember to obtain a true representation when using the count method is to put -1 after, so the code should go something like this....

VB.NET:
If objDS.Tables(0).Rows.Count -1 =  Session("CurrentIndex") Then

Also this code you have used...

VB.NET:
Session("CurrentIndex") = Session("CurrentIndex") + 1

To be used in the best 'spirit' of VB.NET should be...

VB.NET:
Session("CurrentIndex") +=1
 
Counts and object indexes are zero based

You need to remember that positions, and index values (listboxes and comboboxes etc.) are zero based, the first value is zero. Counts give you the actual count, you use .count - 1 when you relate it to a position. If the count = 20 and you want to move to the last item's position you would go to count - 1.
 
Back
Top