I’m trying to make a program that emails the results of a query (in a dataset) to a user… My code is:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Paid_Out_TbTableAdapter.Fill(Me.dataset.Paid_Out_Tb)
Me.ReportViewer1.RefreshReport()
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("Bob", "password")
SmtpServer.Port = 25
SmtpServer.Host = "server"
mail = New MailMessage()
mail.From = New MailAddress("email@email.com")
mail.To.Add("Email@email.com")
mail.Subject = "Test Mail"
mail.Body = (Me.DataSet.Paid_Out_Tb.ToString)
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Everything works except sending the email body… How can i get the results to email as the body?
You can use Linq and VB’s new inline xml literals capability to generate the html. Try this:
Be sure to include a reference to System.Data.DataSetExtensions.dll in your project if it isn’t already there. You’ll also need
Imports System.Linqon your class. See the Using LINQ and XML Literals to transform a DataTable into a HTML table blog posting by Éric Moreau for a good explanation.