Loop through datareader after binding to repeater control

S

sck10

Hello,

I am calling a stored procedure to populate a Repeater Control. What I need
to do is see if a name is in the list and if not, add it to the Repeater.
Is there a way to reset the OleDbDataReader back to the beginning after I
bind it to the Repeater control and then use "If spApproverList.HasRows" to
loop through the reader?

Thanks, sck10


'Open connection to database
Dim cnnSearch As OleDb.OleDbConnection = New
OleDb.OleDbConnection(strConnBsomApps)
cnnSearch.Open()

Dim spApproverList As OleDb.OleDbDataReader
Dim prmApproverList As OleDbParameter
Dim cmdApproverList As New OleDb.OleDbCommand(str00, cnnSearch)
cmdApproverList.CommandType = CommandType.StoredProcedure
'Declare Parameters
prmApproverList = cmdApproverList.Parameters.Add("@strParm01",
OleDbType.VarChar) : prmApproverList.Value = str01

'Data Bind: DropdownList
spApproverList = cmdApproverList.ExecuteReader()
ddlApproverList.DataSource = spApproverList
ddlApproverList.DataTextField = "Handle"
ddlApproverList.DataBind()
'ddlApproverList.Items.FindByValue(Me.hdnWebUser.Value).Selected = True

Dim strHandleText As String = ""
If spApproverList.HasRows Then
Do While spApproverList.Read
If Not IsDBNull(spApproverList("Handle")) Then strHandleText =
CType(spApproverList("Handle"), String)
Loop
End If
 
T

Teemu Keiski

Hi,

data reader is read-only, forward-only. So if you read it to the end once
(like with databinding), you need to requery database in order to loop
through it again. If you want a result set that lasts more than one
iteration, use OleDbdataAdapter to fill a dataTable and loop through the
DataTable.
 
S

sck10

Thanks Teemu...


Teemu Keiski said:
Hi,

data reader is read-only, forward-only. So if you read it to the end once
(like with databinding), you need to requery database in order to loop
through it again. If you want a result set that lasts more than one
iteration, use OleDbdataAdapter to fill a dataTable and loop through the
DataTable.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top