CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Send Email -

Threaded View

  1. #1
    Join Date
    Feb 2009

    Send Email -


    I have the following code;

    Private Function findauthoremail(ByVal name As String) As String
            Dim ConString As String = (ConfigurationManager.ConnectionStrings("CCMSConnectionString").ConnectionString)
            Dim MySQL As String = "Select Email from dbo.TblUser where user_full_name=@user_full_name"
            Dim mijncon As New Data.SqlClient.SqlConnection(ConString)
            Dim Cmd As New Data.SqlClient.SqlCommand(MySQL, mijncon)
            Cmd.Parameters.AddWithValue("@user_full_name", name)
            Dim reader As Data.SqlClient.SqlDataReader = Cmd.ExecuteReader()
            Dim Email As String
            Email = reader("Email")
            Return Email  ' where email is the value you obtained from the database as string
        End Function
    Which I need to read the email address from the database...

    this sub which triggers the email submission;

    Using message As New MailMessage()
                'Dim msgbody As String = String.Empty
                Dim htmlFile As String = Server.MapPath("~/EmailTemplate/ChangeRequest.htm")
                Dim sreader As New StreamReader(htmlFile)
                Dim msgBody As New StringBuilder(sreader.ReadToEnd)
                message.From = New MailAddress(findauthoremail(cmbchngreq.SelectedItem.ToString))
                message.[To].Add(New MailAddress("hh@hotmail.com"))
                message.Subject = "Change Request Enquiry: " + Trim(txtref.Text.ToString())
                message.IsBodyHtml = True
                message.Body = msgBody.ToString
                Dim client As New SmtpClient()
            End Using
    At run time I receive the error -

    System.InvalidOperationException: Invalid attempt to read when no data is present

    Any assistance.. Thanks
    Last edited by dr223; October 31st, 2012 at 06:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.