HI
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)
         Session.Remove("email")
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.[To].Add(recepientEmail)
    mail.Subject = "THE STOCK LOG"
    mail.IsBodyHtml = True
    client.Send(mail)
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
       conn.Open()
       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
       conn.Close()
   End Function

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.