how to traverse through the records using sql datareader
-
We are doing a project in asp.net 2.0 with sql server 2005,we need to move to the next record at the click of a button.We are using an sql datareader,we have one button 'show',to show each record,and in the page load, the following code is there: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load regid.Text = "1" mysql = "select que_bank.que_no,que_bank.ans,testquestions.ans from testquestions,que_bank where que_bank.que_no=testquestions.que_no and testquestions.reg_id='" & regid.Text & "'" cmd.CommandText = mysql myconn.Open() objdr = cmd.ExecuteReader() End Sub Protected Sub show_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles show.Click objdr.Read() queno.Text = objdr.GetValue(0) cans.Text = objdr.GetValue(1) urans.Text = objdr.GetValue(2) End Sub Can anyone help us?
-
We are doing a project in asp.net 2.0 with sql server 2005,we need to move to the next record at the click of a button.We are using an sql datareader,we have one button 'show',to show each record,and in the page load, the following code is there: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load regid.Text = "1" mysql = "select que_bank.que_no,que_bank.ans,testquestions.ans from testquestions,que_bank where que_bank.que_no=testquestions.que_no and testquestions.reg_id='" & regid.Text & "'" cmd.CommandText = mysql myconn.Open() objdr = cmd.ExecuteReader() End Sub Protected Sub show_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles show.Click objdr.Read() queno.Text = objdr.GetValue(0) cans.Text = objdr.GetValue(1) urans.Text = objdr.GetValue(2) End Sub Can anyone help us?
-
We are doing a project in asp.net 2.0 with sql server 2005,we need to move to the next record at the click of a button.We are using an sql datareader,we have one button 'show',to show each record,and in the page load, the following code is there: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load regid.Text = "1" mysql = "select que_bank.que_no,que_bank.ans,testquestions.ans from testquestions,que_bank where que_bank.que_no=testquestions.que_no and testquestions.reg_id='" & regid.Text & "'" cmd.CommandText = mysql myconn.Open() objdr = cmd.ExecuteReader() End Sub Protected Sub show_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles show.Click objdr.Read() queno.Text = objdr.GetValue(0) cans.Text = objdr.GetValue(1) urans.Text = objdr.GetValue(2) End Sub Can anyone help us?
I hope this is a bad practice.. In your code connection is open and seems to be never closed. Best thing to do is to use Paging in Sql server with @rowsPerPage being 1 and @pageNum being row no. hope u understand the concept
----------------- logiclabz