943,907 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1875
  • ASP.NET RSS
Sep 15th, 2008
0

Navigating records thru session variables

Expand Post »
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.

asp.net Syntax (Toggle Plain Text)
  1. Imports System
  2. Imports System.Data
  3. Imports System.Data.SqlClient
After Inherits im writing

asp.net Syntax (Toggle Plain Text)
  1. Dim con as SqlConnection
  2. Dim com as SqlCommand
  3. Dim adp as SqlDataAdapter
  4. Dim data as DataSet

In Page_Load,

asp.net Syntax (Toggle Plain Text)
  1. con = New SqlConnection
  2. con.ConnectionString = "Data Source = ACER;Initial Catalog = Preethi;Inetgrated Security = True
  3. If Not IsPostBack() Then
  4. adp = New SqlDataAdapter("select * from emp",con)
  5. data = New DataSet
  6. adp.Fill(data)
  7. TextBox1.Text = data.Tables(0).Rows(0).Item(0)
  8. TextBox1.Text = data.Tables(0).Rows(0).Item(1)
  9. TextBox1.Text = data.Tables(0).Rows(0).Item(2)
  10. TextBox1.Text = data.Tables(0).Rows(0).Item(3)
  11. con.Open()
  12. Session("Recno") = 0
  13. End If
  14.  

Im having 4 Textbox and 1 dropdownlist box in webform.
In DropDownList1 , doing all opeartions for database connection, and im writing the following text
asp.net Syntax (Toggle Plain Text)
  1. Session("Recno") = DropDownList1.SelectedValue.
  2. DropDowlList1.DataSource = data
  3. DropDownList1.DataTextField = "EmpName"
  4. DropDownList1.DataValueField = "EmpNo"
  5. DropDownList1.DataBind()

I also Placed 4 buttons for NAvigation ,
In Button 1 - First
asp.net Syntax (Toggle Plain Text)
  1. Session("Recno") = 0
  2. PreviousButton.Enabled = False

In Next Button,
asp.net Syntax (Toggle Plain Text)
  1. Session("Recno") = +1
  2. IF Session("Recno") = data.Tables(0).Rows.Count - 1 Then
  3. NextButton.Enabled = false
  4. 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.)
Last edited by peter_budo; Sep 18th, 2008 at 1:07 pm. Reason: Keep It Organized - please use [code] tags as [code]YOUR CODE HERE[/code]
Reputation Points: 10
Solved Threads: 0
Light Poster
preethi_ga is offline Offline
38 posts
since Jun 2008
Sep 16th, 2008
0

Re: Navigating records thru session variables

Hi preety

You can use dataset's row postion to navigate.

Initial instance you can use

dim intRowno as integer
first button
ASP.NET Syntax (Toggle Plain Text)
  1. Session("rowno") = "0"
  2.  
  3. textbox1.text = Mydataset.tables(0).rows(0)("Columnname1").Tostring
  4. textbox2.text = Mydataset.tables(0).rows(0)("Columnname2").Tostring


Next button
ASP.NET Syntax (Toggle Plain Text)
  1. intRowno = Session("rowno") + 1
  2.  
  3. textbox1.text = Mydataset.tables(0).rows(intRowno )("Columnname1").Tostring
  4. textbox2.text = Mydataset.tables(0).rows(intRowno )("Columnname2").Tostring
  5.  
  6. Session("rowno") = intRowno

Prev button
ASP.NET Syntax (Toggle Plain Text)
  1. intRowno =Session("rowno")
  2.  
  3. textbox1.text = Mydataset.tables(0).rows(intRowno -1)("Columnname1").Tostring
  4. textbox2.text = Mydataset.tables(0).rows(intRowno -1)("Columnname2").Tostring

Last button

ASP.NET Syntax (Toggle Plain Text)
  1. intRow= mydataset.rows.count-1
  2.  
  3. textbox1.text = Mydataset.tables(0).rows(mydataset.rows.count-1)("Columnname1").Tostring
  4. textbox2.text = Mydataset.tables(0).rows(mydataset.rows.count-1)("Columnname2").Tostring


I hope this will help you.

Mohammed Yousuf uddin
Software Developer
Last edited by peter_budo; Sep 18th, 2008 at 1:08 pm. Reason: Keep It Organized - please use [code] tags
Reputation Points: 12
Solved Threads: 38
Junior Poster
reach_yousuf is offline Offline
194 posts
since Sep 2007
Sep 22nd, 2008
0

Re: Navigating records thru session variables

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"
Reputation Points: 10
Solved Threads: 0
Light Poster
preethi_ga is offline Offline
38 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Displaying Dialog Box in asp.net
Next Thread in ASP.NET Forum Timeline: Horizontal and vertical centering of a Update panel progress bar in a page. How?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC