473,378 Members | 1,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

For Loop Problem

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

Nov 19 '05 #1
1 1310
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
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:OX**************@TK2MSFTNGP14.phx.gbl...
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
5
by: build | last post by:
G'day All, I have a problem with this loop. There are a number of .txt files in 'myPath'. tmpFile = Dir(myPath & "\*.txt") 'PROCESS FOLDER Do Until tmpFile = "" <lottsa code> <too much to...
11
by: ritterhaus | last post by:
Just a simple bit of code to toggle between two state at intervals... import time for i in range(4): print 'On' time.sleep(1) print 'Off' time.sleep(1) .... SHOULD toggle On and Off four...
12
by: reynoldscraigr | last post by:
Hi All, hope someone can see what wrong here I have the following function function RemoveMenuFromHoldArray(menuName) { var i = 0; for (i=0;i<=MenusToHoldOpen.length-1;i++) { if...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
63
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
15
by: Mike Lansdaal | last post by:
I came across a reference on a web site (http://www.personalmicrocosms.com/html/dotnettips.html#richtextbox_lines ) that said to speed up access to a rich text box's lines that you needed to use a...
2
by: d3vkit | last post by:
Okay so I can NOT get my while loop to work. It's the most confusing thing I've ever come across. It was working fine and then suddenly, nothing. No error. The page just dies. I am using PHP5 with...
5
by: sgurukrupagmailcom | last post by:
Hi, I haven't come accross an elegant solution to a design problem that I show below. Have a look at the piece of code here: class Exc { Exc () { System.out.println ("Haribol"); }
1
by: JavaJon | last post by:
Hello, I'm Jon. I've recently picked up Java after using a "gimmick" programming language called GML ( Game Maker Language ). I've read a lot of tutorials and even a Java for Dummies *.pdf book....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.