I have 3 text boxes that retrieve data from the database and 4 buttons fist, previous, next and last that help me to navigate through the records of the table.
But I have a problem with the code of the button previews and next.
Because when I execute the application, the next button takes only one value (
row=2
) and always when I press the next button it leads me to the second record of the table.
the same thing happens with the previous button, it takes only the first record of the table.
Please tell me what I have made wrong to my code?
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class default
Inherits System.Web.UI.Page
Dim Sql As String
Dim inc As Integer = 0
Dim ds As New DataSet
Dim MaxRows As Integer
Dim SQLConnection As Object
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
NavigateRecords()
End Sub
Private Sub NavigateRecords()
Dim con As New OleDb.OleDbConnection
Dim strCon As String = "Provider=SQLOLEDB; Data Source=192.168.131.72; Initial Catalog=Flex; User ID=sa; Password="
con.ConnectionString = strCon
con.Open()
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Sql = "SELECT * FROM Customer"
da = New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, "Person")
con.Close()
MaxRows = ds.Tables("Person").Rows.Count
txt_name.Value = ds.Tables("Person").Rows(inc).Item("2")
txt_surname.Value = ds.Tables("Person").Rows(inc).Item("3")
txt_city.Value = ds.Tables("Person").Rows(inc).Item("4")
End Sub
Protected Sub btn_next_Click(sender As Object, e As EventArgs) Handles btn_next.Click
If (inc <> (MaxRows - 1)) Then
inc = inc + 1
NavigateRecords()
End If
End Sub
Protected Sub btn_first_Click(sender As Object, e As EventArgs) Handles btn_first.Click
If (inc <> 0) Then
inc = 0
NavigateRecords()
End If
End Sub
Protected Sub btn_previews_Click(sender As Object, e As EventArgs) Handles btn_previews.Click
If (inc > 0) Then
inc = inc - 1
NavigateRecords()
End If
End Sub
Protected Sub btn_last_Click(sender As Object, e As EventArgs) Handles btn_last.Click
If (inc <> (MaxRows - 1)) Then
inc = MaxRows - 1
NavigateRecords()
End If
End Sub
End Class