Saturday, March 24, 2012

Loop through datareader after binding to repeater control

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("@dotnet.itags.org.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.V alue).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 IfHi,

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
"sck10" <sck10@.online.nospamwrote in message
news:O6CYKAd1GHA.4392@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

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.V alue).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
>


Thanks Teemu...

"Teemu Keiski" <joteke@.aspalliance.comwrote in message
news:%23cGy01d1GHA.476@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

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
>
>
"sck10" <sck10@.online.nospamwrote in message
news:O6CYKAd1GHA.4392@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

>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.V alue).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
>>


>
>

0 comments:

Post a Comment