Send Email -
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
    Posts
    190

    Send Email -

    Hi,

    I have the following code;

    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)
            mijncon.Open()
            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;

    Code:
    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)
                sreader.Close()
    
    
                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()
                client.Send(message)
    
                sreader.Dispose()
    
            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 07: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

This is a CodeGuru survey question.


Featured


HTML5 Development Center