Hei,
Im using ASP.NET as Front end and SQL Server as Backend. the codings are..

imports system
imports system.data
imports system.data.sqlclient

After inherits...... some connectin codingd are there

dim con as SqlConnection
dim adp as SqlDataAdapter
dim com as SqlCommand
dim data as Dataset

after the connection codings in Next button the following codings im writing....

dim rec_count as integer = 0
dim row_count as integer = data.Tables(0).Rows.Count - 1 // so by this we will get total number of records.
If rec_count <> row_count Then
rec_count = rec_count + 1
TextBox1.Text = Data.Tables(0).Rows(rec_count).Item(0)
TextBox2.Text = Data.Tables(0).Rows(rec_count).Item(1) 
Else 
MsgBox " This is the Last Record "

Like wise im writing for PREVIOUS BUTTON also, only change is [ rec_count = rec_count - 1 ] By writing this,,, when the first time i click in the Next button , it goes to next record, but when next time i click in Next button ... it doesnt change.
then if i click in PREVIOUS button... It shows error like... "There is no record in position -1".
So many times i asked about this? but im not getting the correct solution. So any one Please get me correct soution??

Well when you click on the button, the page is posted back to the server and you start again with rec_count as 0.

Thus when you click on the Next button, you see only your first record and when you say previous (which is again a button click), it does 0-1= -1 and does not find any corresponding record at that position.

You need to know about State Management in order to get this code working for you. I suggest you store your table in a Session Variable and access it using individual datarows of a datatable.

PS- ASP.NET does not quite work the same way as VB.NET!

Hei,
Im using ASP.NET as Front end and SQL Server as Backend. the codings are..

imports system
imports system.data
imports system.data.sqlclient

After inherits...... some connectin codingd are there

dim con as SqlConnection
dim adp as SqlDataAdapter
dim com as SqlCommand
dim data as Dataset

after the connection codings in Next button the following codings im writing....

dim rec_count as integer = 0
dim row_count as integer = data.Tables(0).Rows.Count - 1 // so by this we will get total number of records.
If rec_count <> row_count Then
rec_count = rec_count + 1
TextBox1.Text = Data.Tables(0).Rows(rec_count).Item(0)
TextBox2.Text = Data.Tables(0).Rows(rec_count).Item(1) 
Else 
MsgBox " This is the Last Record "

Like wise im writing for PREVIOUS BUTTON also, only change is [ rec_count = rec_count - 1 ] By writing this,,, when the first time i click in the Next button , it goes to next record, but when next time i click in Next button ... it doesnt change.
then if i click in PREVIOUS button... It shows error like... "There is no record in position -1".
So many times i asked about this? but im not getting the correct solution. So any one Please get me correct soution??

Alrighty, firstly thanks for the starter code there, I was also searching for this and your code is the only thing that came close to an understandable solution.
So I stole your code sat for 5 hours and with the last cup of coffee at 11pm at just before giving up, came up with this.

You can Start by Using a Session Variable.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Session("Record") = 0
        End If
    End Sub
   
Protected Sub LoadPrevQuestion()
        Dim EmpNo As String = Request.QueryString.Get("No")
        Dim myConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
        Dim MyAdapter As New SqlDataAdapter("SELECT EmpNo, SectionNo, QuestionNo FROM Appraisal WHERE EmpNo='" & EmpNo & "'", myConnection)
        Dim MyDataset As New DataSet()
        MyAdapter.Fill(MyDataset)
Dim rec_count As Integer = Session("Record")
 Dim row_count As Integer = MyDataset.Tables(0).Rows.Count -1 
        Response.Write(row_count.ToString())
        If rec_count <> 0 Then
            Session("Record") = rec_count - 1
            rec_count = rec_count - 1
       Response.Write(MyDataset.Tables(0).Rows(rec_count).Item(2))
       Response.Write(MyDataset.Tables(0).Rows(rec_count).Item(1))
        Else
            Response.Write("first record")
        End If
End Sub
Same story just in reverse.
Protected Sub LoadNextQuestion()
        Dim EmpNo As String = Request.QueryString.Get("No")
        Dim myConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("PAConStr").ConnectionString)
        Dim MyAdapter As New SqlDataAdapter("SELECT EmpNo, SectionNo, QuestionNo FROM Appraisal WHERE EmpNo='" & EmpNo & "'", myConnection)
        Dim MyDataset As New DataSet()
        MyAdapter.Fill(MyDataset)
     Dim rec_count As Integer = Session("Record")
     Dim row_count As Integer = MyDataset.Tables(0).Rows.Count - 1
        Response.Write(row_count.ToString())
        If rec_count <> row_count Then
            Session("Record") = rec_count + 1
            rec_count = rec_count + 1
     Response.Write(MyDataset.Tables(0).Rows(rec_count).Item(2))
     Response.Write(MyDataset.Tables(0).Rows(rec_count).Item(1))
        Else
            Response.Write("Last record")
        End If
End Sub

So I say thank you my friend. You saved me with your need of salvation....

Ill check back in a few days to see if you managed.
L8ter.
J

still am not understanding how to do?

the same code will work if te interger varible(row_cnt) declared as static or store in a viewstate.let me know it works for u?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.