DataRow Iteration

  • Thread starter Thread starter rbutch
  • Start date Start date
R

rbutch

Guys if anyone has an answer to this - i'd appreciate some assistance.
the problem is not building the dataset within String Builder - so i can render it as HTML in the email msg body.
the problem is - the dataset can change and return more or less columns than i have here and my DataRows, Im specifing
certain Indexes.
so, one time the dataset will have say, 5 rows in it and the next time it may have say 12. i'm about at the edge of my expertise right now, so any code examples from an expert would be appreciated - other wise the only thing i can think of is to
build separate Stringbuilder Components and pass a number to them that corresponds with the number of columns retrieved.
i've only included enough of the snippets of code in the procedure - to give clarity. i can send all if need be, but the real problem is in the aRow.Item("index")
thanks again for any help.
rik

Public ds As DataSet
Dim oMailMsg As MailMessage = New MailMessage
Dim sb As New StringBuilder
oMailMsg.BodyFormat = MailFormat.Html

sb.Append("<p><img SRC=C:\SelectLogo.gif></p><br>")
For Each aRow In ds.Tables(0).Rows
sb.Append("<table border=1 cellspacing=3><tr><td>" + aRow.Item(0) + "</td>" + "<td>" + aRow.Item(1) + "</td></tr></table>")
Next
oMailMsg.Body = sb.ToString
SmtpMail.Send(oMailMsg)

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
The DataTable object has a Rows property which is a collection which has a
Count property. With this being known you can use it to loop through the
DataRow.Items collection.

Hope this helps
 
i think my problem is not the Number of rows that are returned, but the number of columns in each row as a result of the query.


that's actually my favorite to use "a DataTable"
which i use something like:
if DataTable.rows.count <=0 then
messagebox.show("Nothing Found")
elseif DataTable.rows.count >=1 then
"do Something"
else
end if

it's when i get to the DataRow Assignment and use the elements.
the index values are hardcoded. like DataRow.Item(0) & DataRow.Item(1) etc.
if i go outside of the index of the columns that the dataset returns, it will blow up. if i say, knew the exact number of columns each dataset/dataTable would return, could i somehow pass that to the Index???? i.e. DataRow.Item(i) - or am i just
wishing on this?
thanks again for the replies
rik






**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
Back
Top