Dim conn As New SqlConnection(connstr1)
Dim sql As String
sql = "Select * from address1"
'Dim da As SqlDataAdapter
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
Dim ds As New DataSet()
da = New SqlDataAdapter(sql, conn)
da.Fill(ds, "Address1")
maxrows = ds.Tables("Address1").Rows.Count
inc = -1
conn.Close()
'If next_record <= maxrows - 1 Then

If inc <> maxrows - 1 Then
inc = inc + 1
'NavigateRecords()
TextBox1.Text = ds.Tables("address1").Rows(inc).Item("rollno").ToString
TextBox2.Text = ds.Tables("address1").Rows(inc).Item("name").ToString
'inc = inc + 1
End If


I am new in vb.net .
I want next record when i Click on Next button Each time .
I am using Vb.net & sql server 2005 as a back end .
please help me .

Dim conn As New SqlConnection(connstr1)
Dim sql As String
sql = "Select * from address1"
'Dim da As SqlDataAdapter
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
Dim ds As New DataSet()
da = New SqlDataAdapter(sql, conn)
da.Fill(ds, "Address1")
maxrows = ds.Tables("Address1").Rows.Count
inc = -1
conn.Close()
If inc <> maxrows - 1 Then
inc = inc + 1
TextBox1.Text = ds.Tables("address1").Rows(inc).Item("rollno").ToString
TextBox2.Text = ds.Tables("address1").Rows(inc).Item("name").ToString
End If

first this code must be written in the next_button (by double click next_button to access its code )
second you need to initiate the variable inc outside the next button code (global variable)
in your code now , each time you click next, inc will be -1 at start and therefore always the same record will be displayed

This article has been dead for over six months. Start a new discussion instead.