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