Navigating records thru session variables

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 38
Reputation: preethi_ga is an unknown quantity at this point 
Solved Threads: 0
preethi_ga preethi_ga is offline Offline
Light Poster

Navigating records thru session variables

 
0
  #1
Sep 15th, 2008
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.

  1. Imports System
  2. Imports System.Data
  3. Imports System.Data.SqlClient
After Inherits im writing

  1. Dim con as SqlConnection
  2. Dim com as SqlCommand
  3. Dim adp as SqlDataAdapter
  4. Dim data as DataSet

In Page_Load,

  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
  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
  1. Session("Recno") = 0
  2. PreviousButton.Enabled = False

In Next Button,
  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]
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 68
Reputation: reach_yousuf is an unknown quantity at this point 
Solved Threads: 13
reach_yousuf reach_yousuf is offline Offline
Junior Poster in Training

Re: Navigating records thru session variables

 
0
  #2
Sep 16th, 2008
Hi preety

You can use dataset's row postion to navigate.

Initial instance you can use

dim intRowno as integer
first button
  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
  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
  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

  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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 38
Reputation: preethi_ga is an unknown quantity at this point 
Solved Threads: 0
preethi_ga preethi_ga is offline Offline
Light Poster

Re: Navigating records thru session variables

 
0
  #3
Sep 22nd, 2008
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"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC