I need to send data from my mssql table to my client by email...
Currently I can send one by one items.(more than 200 items)

Private Sub SendEmail()

         Dim body As String = Me.PopulateBody
         Me.SendHtmlFormattedEmail(Session("email"), ".", body)
End Sub

Private Sub SendHtmlFormattedEmail(ByVal recepientEmail As String, ByVal subject As String, ByVal body As String)
    Dim client As New SmtpClient()
    Dim mail As New MailMessage()
    mail.Body = body
    mail.Subject = "THE STOCK LOG"
    mail.IsBodyHtml = True
End Sub

Private Function PopulateBody() As String
       Dim data As SqlDataReader
       cmd = New SqlCommand
       cmd.Connection = conn
       cmd.CommandText = ("Select itemid, itemdes, balqty from tbl_stock_bal where itemid ='" & Me.txttItemID.Text & "'")
       cmd.CommandType = CommandType.Text
       data = cmd.ExecuteReader

       If (data.Read) Then
           Dim itemid As String = data.Item("itemid")
           Dim itemdes As String = data.Item("itemdes")
           Dim qty As String = data.Item("balqty")

       Dim body As String = String.Empty
       'Dim mail As New MailMessage()
       Dim reader As StreamReader = New StreamReader(Server.MapPath("Materials.html"))
       body = reader.ReadToEnd
       body = body.Replace("{Date}", Date.Now)
       body = body.Replace("{itemid}", itemid)
       body = body.Replace("{itemdes}", itemdes)
       body = body.Replace("{balqty}", qty)
       Session("email") = "maideen5@hotmail.com"
       Return body
End If
       cmd = Nothing
   End Function

Below is my code. It is working fine but one by one
pls advice me...

Edited by Maideen: for Improve information

1 Year
Discussion Span
Last Post by hericles

Are you trying to send an email that has all of the items in it?
If yes, alter your query to return all rows (i.e. all relevant items) and run through each row, parsing the data, and adding it onto the body string.
I'd switch to using a DataAdaptor and a DataTable for that (my personal preference) and process over them all.
You'll want to alter your HTML generated string to style the results better of course.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.