|
 |
|
 |
01-31-2006, 07:17 AM
|
#1 (permalink)
|
|
Registered User
Join Date: Jan 2006
Posts: 29
|
Email a Dataset or DataTable
hey guys, i'm in need of some serious help here.
i've got a project with little time to research and barely enough time to code.
i know this may sound simple to you guys, and that's great.
all help is appreciate and i'm picking up lunch for this.
the .exe will run as a service and seach a database every 60 seconds for records based on a condtion.
if condition exists, fetch the records and send an email.
i need to retrieve these records from a database as a dataset or datatable and then put those records in the Body of an email.
i have to display them in table form + insert a logo as well. and im thinking i need to use something like.
oMailMsg.BodyFormat = MailFormat.Html
i've had no success embedding the .jpg in the email when i dont use MailFormat.Html.
my Problem is handling the data retrieved - since it will be a collection and needs to fit neatly in a table w/ borders format.
thanks for any help
rik
Can Anyone help or direct me to a solution that can do this?
|
|
|
01-31-2006, 07:37 AM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
|
If you're confident with reading code, the Dynamicaly table article, might give you some idear, on how to form the data retrieved, else, yes you will need the MailFormat.Html in order to have images included inside the mail, theres no way to show an image in a TXT formed mail.
|
|
|
01-31-2006, 01:18 PM
|
#3 (permalink)
|
|
Registered User
Join Date: Jan 2006
Posts: 29
|
figured this out
Actually that was no help but i was able to figure this out using Stringbuilder
Append Property and Use Html code and a Datarow to loop thru my dataset.
see below thanks
rik
Dim sb As New StringBuilder
oMailMsg.BodyFormat = MailFormat.Html
Dim aRow As DataRow
sb.Append("<p><img SRC=C:\SelectLogo.gif></p><br>")--Image embeded
For Each aRow In ds.Tables(0).Rows
sb.Append("<table border=1><tr><td>" + aRow.Item(0) + "</td>" + "<td>" + aRow.Item(1) + "</td></tr></table>")
Next
oMailMsg.Body = sb.ToString
|
|
|
01-31-2006, 01:48 PM
|
#4 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
|
Well, your first post didn't tell anything on how the input data was formed, and how you wanted it displayed in your table, I just assumed you were having trouble building a dynamic table from your fetched data.
On another note, you could make it:
Code:
Dim sb As New StringBuilder
oMailMsg.BodyFormat = MailFormat.Html
Dim aRow As DataRow
sb.Append("<p><img SRC=C:\SelectLogo.gif></p><br>") --Image embeded
sb.Append("<table border=1>")
For Each aRow In ds.Tables(0).Rows
sb.Append("<tr><td>" + aRow.Item(0) + "</td>" + "<td>" + aRow.Item(1) + "</td></tr>")
Next
sb.Append("</table>")
oMailMsg.Body = sb.ToString
For a nicer output.
|
|
|
02-01-2006, 09:16 AM
|
#5 (permalink)
|
|
Registered User
Join Date: Jan 2006
Posts: 29
|
i like that. thanks, im in a completely new area for me. would you happen to know how i could make the Index elements recursive? in other words, i'm guessing i would need a for loop and dependent on how many rows were returned, the indexes of the DataRow would just use the number passed from the for loop.
so, instead of aRow.Item(0) & aRow.Item(1) ---hardcoded for two elements only
i could have somethng like aRow.Item(i)
which of course would correspond to a For i = 0 to "someNumber"
thanks again
rik
|
|
|
02-01-2006, 11:30 AM
|
#6 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
|
Now I have no idear what specific language this is in, but from the small code examples you've shown here, I'm guessing VB, it's been a while since I've touched that, but something like:
Code:
...
Dim sb As New StringBuilder
Dim rows As Integer
Dim colums As Integer
Dim i As Integer
Dim j As Integer
...
oMailMsg.BodyFormat = MailFormat.Html
rows = ds.Tables.Rows.Count
columns = ds.Tables.Columns.Count
sb.Append("<p><img SRC=C:\SelectLogo.gif></p><br>")
sb.Append("<table border=1>")
For i = 0 To rows
sb.Append("<tr>")
For j = 0 To columns
sb.Append("<td>" + ds.Tables(i).Item(j) + "</td>")
Next j
sb.Append("</tr>")
Next i
sb.Append("</table>")
might give you a hint on where I'm going with how you can access the items in a NxM table.
|
|
|
02-01-2006, 11:47 AM
|
#7 (permalink)
|
|
Registered User
Join Date: Jan 2006
Posts: 29
|
yes it's vb.net - basically im declaring a datarow - assigning a dataset and iterating thru those rows. you can get to the elements of each row (aRow.Item(0)) and as long as you dont as for more elements than are in the dataset, you're okay.
if i'm doing a select for say: select myName,MyAddress from SomeTable.
and i assign that to a datset then to a datarow, as long as i dont ask for::
aRow.Item(2) - im okay - if i ask for that third item - "it out of the Index Range"
thanks again for your help on this
rik
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 11:28 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|