Hi,
Im using ASP.NET as front end and SQL SERVER as backend. i navigate the records in this using session variables. but its not working.

Imports System
Imports System.Data 
Imports System.Data.SqlClient

After Inherits im writing

Dim con as SqlConnection
Dim com as SqlCommand
Dim adp as SqlDataAdapter
Dim data as DataSet

In Page_Load,

con = New SqlConnection
con.ConnectionString = "Data Source = ACER;Initial Catalog = Preethi;Inetgrated Security = True
If Not IsPostBack() Then
adp = New SqlDataAdapter("select * from emp",con) 
data = New DataSet 
adp.Fill(data)
TextBox1.Text = data.Tables(0).Rows(0).Item(0)
TextBox1.Text = data.Tables(0).Rows(0).Item(1) 
TextBox1.Text = data.Tables(0).Rows(0).Item(2) 
TextBox1.Text = data.Tables(0).Rows(0).Item(3)
con.Open() 
Session("Recno") = 0 
End If

Im having 4 Textbox and 1 dropdownlist box in webform.
In DropDownList1 , doing all opeartions for database connection, and im writing the following text

Session("Recno") = DropDownList1.SelectedValue. 
 DropDowlList1.DataSource = data 
 DropDownList1.DataTextField = "EmpName" 
 DropDownList1.DataValueField = "EmpNo" 
DropDownList1.DataBind()

I also Placed 4 buttons for NAvigation ,
In Button 1 - First

Session("Recno") = 0 
 PreviousButton.Enabled = False

In Next Button,

Session("Recno") = +1 
 IF Session("Recno") = data.Tables(0).Rows.Count - 1 Then 
 NextButton.Enabled = false 
 MsgBox("Last Record")

But with this code it is not working , webpage remains same, not moving to next record.
And same for Previous also, it doesnt work.

For Previous Button im giving Session("Recno") = -1 For LAst Button, Session("Recno") = data.Tables(0).Rows.Count - 1 So the Records i cant navigate, can any one help me solve this problem????????
(for the past 6 months im searching, but im not getting the correct solution.)

Recommended Answers

All 2 Replies

Hi preety

You can use dataset's row postion to navigate.

Initial instance you can use

dim intRowno as integer
first button

Session("rowno") = "0"

textbox1.text = Mydataset.tables(0).rows(0)("Columnname1").Tostring
textbox2.text = Mydataset.tables(0).rows(0)("Columnname2").Tostring

Next button

intRowno = Session("rowno") + 1

textbox1.text = Mydataset.tables(0).rows(intRowno )("Columnname1").Tostring
textbox2.text = Mydataset.tables(0).rows(intRowno )("Columnname2").Tostring

 Session("rowno")  = intRowno

Prev button

intRowno  =Session("rowno")  

textbox1.text = Mydataset.tables(0).rows(intRowno -1)("Columnname1").Tostring
textbox2.text = Mydataset.tables(0).rows(intRowno -1)("Columnname2").Tostring

Last button

intRow= mydataset.rows.count-1

textbox1.text = Mydataset.tables(0).rows(mydataset.rows.count-1)("Columnname1").Tostring
textbox2.text = Mydataset.tables(0).rows(mydataset.rows.count-1)("Columnname2").Tostring

I hope this will help you.

Mohammed Yousuf uddin
Software Developer

hi ,
I tried that. but still im getting error. actually im organizing the dataset from AddNewItem. so the dataset came like Dataset1. if i Add another dataset, then it will come like Dataset2.
So,
for the first time i gave in Page_load,
[ TextBox1.Text = Data.Tables(0).Rows(o)("ColumnName1").ToString ]
then it showed me,
" Table cannot found "
tthen i gave
[ TextBox1.Text = Data.Tables(1).Rows(0)("ColumnName1").ToString ]
then all data retrieved.

but in Next button
[ InitRecPos = session("recno") + 1 ]

[ TextBox1.Text = Data.Tables(1).Rows(InitRecPos)("ColumnName1").ToString ]
it shows
" Table 1 cannot found "
after that
i type
[ TextBox1.Text = Data.Tables(0).Rows(InitRecPos)("ColumnName1").ToString ]

Again it showed
" There is no row at position 1"

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.