473,395 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Move next and back through rows using datareader in ASP.Net

I have multiple dropdownlists each one filled with values from a specific column in the table. Also I have multiple textboxes corresponding to dropdownlists. For example, when I select an item from dropdownlistA, all the textboxes are filled with the first row values that contains that selected item and gives the number of rows containing this value……. In addition, I have 2 buttons one is Move Forward Button and the other is Move Previous…I am using a Record Set and don’t know how to move next and back throughout the selected rows…could you help me please? I am using a vb codebehind…

Part of the code:

I have 6 dropdownlists like the following,
Private Sub fillDropDownList3()
Dim sqlString As String = "select * from ItemName"
Dim cmd As New SqlCommand(sqlString, conn)
cmd.CommandType = CommandType.Text
Dim dr As SqlDataReader
conn.Open()
dr = cmd.ExecuteReader
While dr.Read
Me.DropDownList3.Items.Add(dr(0))
End While
dr.Close()
conn.Close()

Private Sub DropDownList3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList3.SelectedIndexChanged
Dim count As IntegerDim sqlString As String = " select * from ReceiptItems where ItemName=@ItemName"Dim cmd As New SqlCommand(sqlString, conn)
cmd.CommandType = CommandType.Text
cmd.Parameters.Add("@ItemName", Me.DropDownList3.SelectedItem.Text)
Dim dr As SqlDataReader
conn.Open()
dr = cmd.ExecuteReader
While dr.Read()
count = count + 1
Me.TextBox3.Text = dr("Name")
Me.TextBox4.Text = dr("Dept")
Me.TextBox5.Text = dr("ItemName")
Me.TextBox6.Text = dr("ItemDescription")
Me.TextBox7.Text = dr("ItemSN")
Me.TextBox8.Text = dr("Date")
End While
dr.Close()
conn.Close()
Me.TextBox2.Text = count
End Sub
but in the textbox corresponding to it, it just gives the first result. What I need is to know how to move to the next record, or get back to the previous one by clicking a button....
Thanks
Sep 18 '07 #1
3 14362
nateraaaa
663 Expert 512MB
I have multiple dropdownlists each one filled with values from a specific column in the table. Also I have multiple textboxes corresponding to dropdownlists. For example, when I select an item from dropdownlistA, all the textboxes are filled with the first row values that contains that selected item and gives the number of rows containing this value……. In addition, I have 2 buttons one is Move Forward Button and the other is Move Previous…I am using a Record Set and don’t know how to move next and back throughout the selected rows…could you help me please? I am using a vb codebehind…

Part of the code:

I have 6 dropdownlists like the following,
Private Sub fillDropDownList3()
Dim sqlString As String = "select * from ItemName"
Dim cmd As New SqlCommand(sqlString, conn)
cmd.CommandType = CommandType.Text
Dim dr As SqlDataReader
conn.Open()
dr = cmd.ExecuteReader
While dr.Read
Me.DropDownList3.Items.Add(dr(0))
End While
dr.Close()
conn.Close()

Private Sub DropDownList3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList3.SelectedIndexChanged
Dim count As IntegerDim sqlString As String = " select * from ReceiptItems where ItemName=@ItemName"Dim cmd As New SqlCommand(sqlString, conn)
cmd.CommandType = CommandType.Text
cmd.Parameters.Add("@ItemName", Me.DropDownList3.SelectedItem.Text)
Dim dr As SqlDataReader
conn.Open()
dr = cmd.ExecuteReader
While dr.Read()
count = count + 1
Me.TextBox3.Text = dr("Name")
Me.TextBox4.Text = dr("Dept")
Me.TextBox5.Text = dr("ItemName")
Me.TextBox6.Text = dr("ItemDescription")
Me.TextBox7.Text = dr("ItemSN")
Me.TextBox8.Text = dr("Date")
End While
dr.Close()
conn.Close()
Me.TextBox2.Text = count
End Sub
but in the textbox corresponding to it, it just gives the first result. What I need is to know how to move to the next record, or get back to the previous one by clicking a button....
Thanks
You cannot use a datareader because it is forward only. Where do you specify your dataset? If you want the 2nd row in the dataset you will need to create a session variable to hold the value of the row you want to display. Now access this row item in your dataset and assign your textboxes the values in that row.

Expand|Select|Wrap|Line Numbers
  1. Me.TextBox3.Text = DataSet.Tables(0).Rows(i)("Name").ToString
Repeat for each textbox.

Nathan
Sep 18 '07 #2
shweta123
692 Expert 512MB
Hi,

Have a look at this example

Link



I have multiple dropdownlists each one filled with values from a specific column in the table. Also I have multiple textboxes corresponding to dropdownlists. For example, when I select an item from dropdownlistA, all the textboxes are filled with the first row values that contains that selected item and gives the number of rows containing this value……. In addition, I have 2 buttons one is Move Forward Button and the other is Move Previous…I am using a Record Set and don’t know how to move next and back throughout the selected rows…could you help me please? I am using a vb codebehind…

Part of the code:

I have 6 dropdownlists like the following,
Private Sub fillDropDownList3()
Dim sqlString As String = "select * from ItemName"
Dim cmd As New SqlCommand(sqlString, conn)
cmd.CommandType = CommandType.Text
Dim dr As SqlDataReader
conn.Open()
dr = cmd.ExecuteReader
While dr.Read
Me.DropDownList3.Items.Add(dr(0))
End While
dr.Close()
conn.Close()

Private Sub DropDownList3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList3.SelectedIndexChanged
Dim count As IntegerDim sqlString As String = " select * from ReceiptItems where ItemName=@ItemName"Dim cmd As New SqlCommand(sqlString, conn)
cmd.CommandType = CommandType.Text
cmd.Parameters.Add("@ItemName", Me.DropDownList3.SelectedItem.Text)
Dim dr As SqlDataReader
conn.Open()
dr = cmd.ExecuteReader
While dr.Read()
count = count + 1
Me.TextBox3.Text = dr("Name")
Me.TextBox4.Text = dr("Dept")
Me.TextBox5.Text = dr("ItemName")
Me.TextBox6.Text = dr("ItemDescription")
Me.TextBox7.Text = dr("ItemSN")
Me.TextBox8.Text = dr("Date")
End While
dr.Close()
conn.Close()
Me.TextBox2.Text = count
End Sub
but in the textbox corresponding to it, it just gives the first result. What I need is to know how to move to the next record, or get back to the previous one by clicking a button....
Thanks
Sep 18 '07 #3
Plater
7,872 Expert 4TB
Aye, you should create one DataTable(or DataSet if that's your fancy) with all the Data in it you need.
Then each of your textboxes/dropdowns/whatevers can pull data from that, and you can move forward and backwards simply by changing the index of the Row (as mentioned in the above post)
Sep 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Hung Huynh | last post by:
Hi, I'm trying to use either one of these methods to position the cursor in a specific position inside a recordset, but neither one seems to work. For example, I have 10 records in my rsData...
1
by: David Whitehouse | last post by:
I've used an SQL staement to pull a table from my database using the DataReader. ie SELECT * FROM Table. However i cannot get off the first row of the table. Is there a DataReader.Next() statement...
14
by: Jacko | last post by:
Hi guys, Say I made a SELECT statement to my sql DB that would return 50 rows that I will use a sqldatareader to access. Instead of iterating through each and every row of the datareader, I'd...
7
by: tshad | last post by:
Is there a way to move a row in a Datalist up or down without having to re-read the data? I have a datalist which has embedded Datagrids in it. I want to allow the user to move a row up or down...
1
by: Phil Endecott | last post by:
Dear Postgresql experts, According to the documentation for MOVE, it returns the number of rows that it has moved over. It seems to me that this is true for MOVE FORWARD n, but not for MOVE...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
14
by: jehugaleahsa | last post by:
Hello: I am working with Oracle .NET Stored Procedures. I would like to know how to return the results of a SELECT statement. I have tried returning a OracleRefCursor and a DataTable, but...
3
by: jaeden99 | last post by:
I was wandering if nyone has a script to move files older than x days old? i've seen several to delete, but I don't want to delete. I would like to create a backup of the files first verify with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.