Mailing SQL Server data

fotini

Active member
Joined
Jun 3, 2003
Messages
39
I know that with the following code in VB.NET you can send a mail
Code:
Dim myMailServer As SmtpMail
Dim myMessage As New MailMessage()
 
myMessage.BodyFormat = MailFormat.Text  
myMessage.Priority = MailPriority.Normal
myMessage.From = "xxx@apn-automation.com"
myMessage.To = "yyy@yahoo.fr" To Address 
myMessage.Subject = msgSubject
myMessage.Body = body
myMessage.Attachments.Add(...)
myMailServer.SmtpServer = "mySMTPserver" 
myMailServer.Send(myMessage)
            
myMessage = Nothing

What I want to do:

retrieve data from a database (with a SELECT) and mail them. How? I cant attach them because there arent in a file, I cant put it to message body because there are not a string.
Please tell me the solution. (I want to mail a DataTable)

P.S. I dont want to make them in a file
 
Does the data need to be in any particualr format? If not you could just set the documents body to DataTable.GetXML. Otherwise you will have to loop through the results and append them to the document yourself.
 
I have an object DataTable but there is not a method Get XML
I tried to append tha data myself to the document with StringBuilder.append but the mail that I recieve is empty!

sb= New StringBuilder
Dim myReader As SqlDataReader = command.ExecuteReader()
While myReader.Read()
sb.append=myReader.GetValue(0)
sb.append="vbCrLf"
End While
 
Sorry - was thinking about datasets not datatables.
Not sure why the e-mail is blank. What code are you using to add the string to the e-mail as the code to build the string looks fine. If you step through in a debugger are the contents being appended to sb?
 
Back
Top