473,394 Members | 1,734 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,394 software developers and data experts.

loop through rows in a table

dim tblrow as System.Data.DataRow
dim i as integer
i = 0
for each tblrow in datasrc.tables(0)
if tblrow.item("Answer").toupper = "OTHER"
i+=1
end if
Next

This seems clear enough to me. Look at all the "Answers" in a table,
if you find "otHer" then increment 'i'

however the great ASP.framework (who we all serve) says
"Compiler Error Message: BC32023: Expression is of type
'System.Data.DataTable', which is not a collection type."

which may well be true.

Tell me how to do this properly please!

Cheers as ever
Fragg
Nov 18 '05 #1
2 6163
Try this... it might work better..

Dim dt as new DataTable = datasrc.Tables(0)
Dim row as DataRow
Dim i as Integer = 0

For Each row in dt.Rows
If cStr(row("Answer")).ToUpper = "OTHER" then
i += 1
End If
Next

HTH,

Bill P.
"Fraggle" <Fr************@yahoo.com> wrote in message
news:ce**************************@posting.google.c om...
dim tblrow as System.Data.DataRow
dim i as integer
i = 0
for each tblrow in datasrc.tables(0)
if tblrow.item("Answer").toupper = "OTHER"
i+=1
end if
Next

This seems clear enough to me. Look at all the "Answers" in a table,
if you find "otHer" then increment 'i'

however the great ASP.framework (who we all serve) says
"Compiler Error Message: BC32023: Expression is of type
'System.Data.DataTable', which is not a collection type."

which may well be true.

Tell me how to do this properly please!

Cheers as ever
Fragg

Nov 18 '05 #2
It works because he is referenceing dt.rows (the rows collection of
the datatable), but you were just referencing the table itself
(datasrc.tables(0)). You have to refer to the rows collection, for
that is what you want to iterate through.
Fr************@yahoo.com (Fraggle) wrote in message news:<ce**************************@posting.google. com>...
"Bill Priess" <no*****@nospam.com> wrote in message news:<u6**************@TK2MSFTNGP11.phx.gbl>...
"Fraggle" <Fr************@yahoo.com> wrote in message
news:ce**************************@posting.google.c om...
dim tblrow as System.Data.DataRow
dim i as integer
i = 0
for each tblrow in datasrc.tables(0)
if tblrow.item("Answer").toupper = "OTHER"
i+=1
end if
Next

This seems clear enough to me. Look at all the "Answers" in a table,
if you find "otHer" then increment 'i'

however the great ASP.framework (who we all serve) says
"Compiler Error Message: BC32023: Expression is of type
'System.Data.DataTable', which is not a collection type."

which may well be true.

Tell me how to do this properly please!

Cheers as ever
Fragg

Try this... it might work better..

Dim dt as new DataTable = datasrc.Tables(0)
Dim row as DataRow
Dim i as Integer = 0

For Each row in dt.Rows
If cStr(row("Answer")).ToUpper = "OTHER" then
i += 1
End If
Next

HTH,

Bill P.

It did indeed, I had to put this line in instead

Dim dt as DataTable = datasrc.Tables(0)

ie take the 'new' out, but then it works fine.

I am a bit unsure on why what you did makes the difference! but cheers

Fragg

Nov 18 '05 #3

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

Similar topics

4
by: jeffsal | last post by:
I am using sorttable.js to sort a table which works fine which allows a user to sort the table by clicking on the column header. Is there some code I could add to the page (onload or something) to...
10
by: VA | last post by:
I got the following function to swap table columns from somewhere on the Internet function swapColumns (table, colIndex1, colIndex2) { if (table && table.rows && table.insertBefore && colIndex1...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
1
by: shankwheat | last post by:
I'm creating a dynamic table with asp and I would like to add a "Show All" and "Collapse All" feature to show/hide certain rows within the table. This code works well for showing/hiding one row at...
2
by: Steve | last post by:
Hi All: I've managed to get myself into something I thought would be simple, and is turning out not to be, or I am too close to the trees to see the forest. I am creating a recordset from a...
8
by: johkar | last post by:
I would like to ensure this script is optimized (runs correctly or does not execute) for the major browsers. Will checking getElementById and getElementsByTagName accomplish this? In addition,...
1
by: emlj001 | last post by:
I have a form that starts at page, http://www.scmeachoraldiv.org/allstate/registration/default.asp My problem is on the page http://www.scmeachoraldiv.org/allstate/registration/part2.asp I...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
by: carolyns | last post by:
I am working with Access 2000, on Windows XP (all updates). I designed a survey in Word with 150+ questions. Roughly 60 questions use a lookup list of 7 different responses. I have the survey...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.