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
FraggTry 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" <Fraggle_Rock_1@.yahoo.com> wrote in message
news:ce92a71b.0311190849.19fea678@.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
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.
Fraggle_Rock_1@.yahoo.com (Fraggle) wrote in message news:<ce92a71b.0311231653.6b0cd9eb@.posting.google.com>...
> "Bill Priess" <no.spam@.nospam.com> wrote in message news:<u6SxI5rrDHA.3140@.TK2MSFTNGP11.phx.gbl>...
> > "Fraggle" <Fraggle_Rock_1@.yahoo.com> wrote in message
> > news:ce92a71b.0311190849.19fea678@.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
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment