For Loop Problem

S

Shapper

Hello,

I have this loop:

For Each row As DataRow In dsContent("pagename").Tables(0).Rows
Dim div As HtmlGenericControl =
CType(Page.FindControl(row("tag_name").ToString), HtmlGenericControl)
If row("content").ToString <> "" Then
div.InnerHtml = row("content").ToString
Else
div.InnerHtml = "&nbsp;"
End If
Next

dsContent("pagename") is a function which returns a dataset where @page
= "pagename"

The strange thing is when there are no records with "pagename" I get na
error in:
div.InnerHtml = row("content").ToString

But why is the For loop running if there are no records.

This is very strange.

Any idea?

Thanks,
Miguel
 
T

Trevor Benedict R

This Code works

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

For Each myRow As DataRow In DSKey.Tables(0).Rows
Response.Write(myRow("TT"))
Next
End Sub

Private Function DSKey() As DataSet
Dim dsLocalKey As New DataSet
Dim dtTmp As New DataTable
dsLocalKey.Tables.Add(dtTmp)
Return dsLocalKey
End Function

This means that you are returning atleast 1 row through the function call
but something that does not have the corresponding column name. Have you
tried to debug the code and also checked the Rows.Count property.

Regards,

Trevor Benedict R
MCSD
 

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,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top