|
-
Feb 18th, 2010, 10:13 AM
#1
Thread Starter
Lively Member
[RESOLVED] Query Results to e-Mail
I know this has probibly been asked before but I have had no luck finding an answer or example anywhere for what I want to do. Which Is.....
I have a query that returns Lname, Fname, and EMail
I want to send 1 email (that Is already set up and working) that contains the results of the query as part of the body that includes an additional message;
"The persons listed below.........." Need to know how to get them "listed below".
then I want to send a seprate e-mail to each email address the query returns, sepratly not in a group but the same message.
any help, examples or links would be appreciated.
Thanks
-
Feb 18th, 2010, 10:31 AM
#2
Re: Query Results to e-Mail
Take the result (is if in a datareader or DataTable) and go though each row.
Append the fields of each row into a string var. Start the string var with:
The persons listed below.........
then Set that result to the body text of the eamil
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 18th, 2010, 11:15 AM
#3
Thread Starter
Lively Member
Re: Query Results to e-Mail
Gary,
I know this isn't right, but am I going in the right direction?
Code:
Dim strBuilder As New System.Text.StringBuilder
strBuilder.Append("The following Persons....."(table.Rows))
-
Feb 18th, 2010, 11:24 AM
#4
Re: Query Results to e-Mail
You are starting.
Is the result set a DataTable or a DataReader?
You cycle though each row. Adding each field to the string.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 18th, 2010, 11:28 AM
#5
Thread Starter
Lively Member
Re: Query Results to e-Mail
-
Feb 18th, 2010, 11:43 AM
#6
Re: Query Results to e-Mail
What is the code that brings back the result set?
da.Fill?
When you have a datatable you have a method called RowCount().
You do a for loop and read each line of the resulting DataTable
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 18th, 2010, 11:58 AM
#7
Thread Starter
Lively Member
Re: Query Results to e-Mail
using an OledbDataAdapter to fill dataTable
Trying something like this will it work?
Code:
Dim strBuilder As New System.Text.StringBuilder
For Each row As DataRow In table.Rows
strBuilder = New System.Text.StringBuilder
For Each col As DataColumn In table.Columns
' Output the value of each column's data.
strBuilder.Append("The following Persons....."(row(col).ToString() & ", "))
Next
Next
Then just but the string value in the eMail body?
-
Feb 18th, 2010, 12:02 PM
#8
Re: Query Results to e-Mail
Move this:
strBuilder = New System.Text.StringBuilder
outside the loop
at the end of the the inside loop add
strBuilder.System.Enviorment.NewLine
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 18th, 2010, 12:10 PM
#9
Thread Starter
Lively Member
Re: Query Results to e-Mail
strBuilder.System.Enviorment.NewLine
is not a member of System.Text.StringBuilder
-
Feb 18th, 2010, 12:13 PM
#10
Re: Query Results to e-Mail
Sorry should be strBuilder.Append (System.Evniorment.NewLine)
That will place each row on its own line.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 18th, 2010, 12:18 PM
#11
Thread Starter
Lively Member
Re: Query Results to e-Mail
Ok Great now how do I get it to the body of my email?
I know I can't just say body = strBuilder
-
Feb 18th, 2010, 12:32 PM
#12
Re: Query Results to e-Mail
Have you done email yet in an application?
You will need to set this all up to be able to use it.
You will need to say what the SMTP server name is, If there are passwords and usernames involved. What the email program is.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 18th, 2010, 12:35 PM
#13
Thread Starter
Lively Member
Re: Query Results to e-Mail
Have it all set up and it works using Outlook
-
Feb 18th, 2010, 12:36 PM
#14
Thread Starter
Lively Member
Re: Query Results to e-Mail
just nee to know how to get what I just did in the body of the message
-
Feb 18th, 2010, 12:37 PM
#15
Re: Query Results to e-Mail
Then you should just be able to assign the resulting string to the body of the mail message.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 18th, 2010, 12:47 PM
#16
Thread Starter
Lively Member
Re: Query Results to e-Mail
Just tried to run it got an "InvalidCastException" Here
Code:
strBuilder.Append("The following Persons....."(row(col).ToString() & ", "))
Conversion from String "GORDEN" to type integer is not valid
-
Feb 18th, 2010, 01:03 PM
#17
Re: Query Results to e-Mail
vb.net Code:
strBuilder.Append("The following Persons....."
strBuilder.Append(System.Enviorment.NewLine)
Dim iCols as Integer = table.Coumns.Count() -1
For iRow as Integer = 0 to table.Rows.RowCount()-1
For Each iCol as Integer = 0 to iCols
strBuilder.Append(table.Rows(iRow).Item(iCol).ToString() & ", ")
Next
strBuilder.Append(System.Enviorment.NewLine)
Next
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 18th, 2010, 01:13 PM
#18
Thread Starter
Lively Member
Re: Query Results to e-Mail
I doesn't like the = in For Each iCol as Integer = 0 to iCols
Syntax error
-
Feb 18th, 2010, 01:19 PM
#19
Re: Query Results to e-Mail
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 18th, 2010, 01:23 PM
#20
Thread Starter
Lively Member
Re: Query Results to e-Mail
That seems to be working
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|