469,616 Members | 2,559 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

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 13737
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

Post your reply

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

Similar topics

1 post views Thread by David Whitehouse | last post: by
7 posts views Thread by tshad | last post: by
1 post views Thread by Phil Endecott | last post: by
10 posts views Thread by Robert | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.