Click here to Skip to main content
16,017,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is wrong in the following code for previous button?
please answer me.
If n = dt.Rows.Count Then
n = 0
Else
tbid.Text = dt.Rows(n).Item("ID").ToString
tblocation.Text = dt.Rows(n).Item("Location").ToString
cboprovince.Text = dt.Rows(n).Item("Province").ToString
tbtype.Text = dt.Rows(n).Item("Type").ToString
tbwidth.Text = dt.Rows(n).Item("Width").ToString
tbheight.Text = dt.Rows(n).Item("Height").ToString
tbremarks.Text = dt.Rows(n).Item("Remarks").ToString
'PictureBox1.Image = dt.Rows(n).Item("Photo").ToString
Dim billboardimage() As Byte = CType(dt.Rows(n).Item("Photo"), Byte())
Dim ms As New MemoryStream(billboardimage)
PictureBox1.Image = Image.FromStream(ms)
n -= 1
End If
Posted
Updated 28-Jun-14 21:45pm
v2

1 solution

Um.

You don't see it?
Suppose you have three items, and you are viewing the second:
n == 1
Count == 3
You execute your code, and n becomes n - 1 : now n == 0
You execute your code, and n is checked against 3, it isn't, so you continue and n becomes n - 1 : now n == -1
You execute your coed, and check n agains 3. It still isn't, so you continue....and n continues to get more and more negative (well, actually it won't, because your app will crash the moment it is negative, but you get the idea...)

Please, learn to use the debugger, and follow your code through: if you had, you would have spotted this yourself in a couple of seconds!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900