Need Help with DataReader. Thanks.

  • Thread starter Thread starter Shapper
  • Start date Start date
S

Shapper

Hello,

I created a code in VB which fills div's in HTML with content stored in
a database using a dataset:

' Populate Dynamic Content Div's
For Each row As DataRow In dsContent("index").Tables(0).Rows
Dim div As HtmlGenericControl = CType(Page.FindControl("d" &
row("name").ToString), HtmlGenericControl)
If row("content_" & Session("culture")).ToString <> "" Then
div.InnerHtml = row("content_" & Session("culture")).ToString
Else
div.InnerHtml = "&nbsp;"
End If
Next

I am having huge problems in making this work with a datareader.

It's not just the "For" loop but also the code line:
CType(Page.FindControl("d" & row("name").ToString), HtmlGenericControl)

Can someone help me out?

Thank You,
Miguel
 
Hi,

If you want to do this with data reader you can't have a for loop like
that. That is fine if you are using a dataset.

If you are using a datareader then perhaps you should write your loop
like....

// dr is datareader and read function returns true or false depending
upon if there are
// rows left or not.
while(dr.Read())
{
// do your job here.
}

HTH,

Regards,
Angrez
 
Back
Top