A
Andy Sutorius
Hi,
I am receiving the error when compiling the project, "cannot implicitly
convert type object to string".
The error points to this line of code and underlines the
dtrRecipient["Email"]: objMailMessage.To = dtrRecipient["Email"];
I'm not sure why I am getting this error. Below is the complete code I am
working with.
private void EmailEm()
{
string intSelectedEmail = ddlChooseEmail.SelectedValue.ToString();
string sqlGetEmail = "SELECT content, subject FROM tblContent WHERE id =
" + intSelectedEmail;
SqlCommand cmdGetEmail = new SqlCommand(sqlGetEmail, strConnString);
SqlDataReader dtrEmail = cmdGetEmail.ExecuteReader();
string intSelectedGroup = chkGroups.SelectedValue.ToString();
string sqlRECIPIENTS = "SELECT tblRecipients.Email AS Email FROM tblGR
INNER JOIN tblRecipients ON tblGR.RecipientID = tblRecipients.ID WHERE
tblGR.GroupID=" + intSelectedGroup;
SqlCommand cmdSelect = new SqlCommand( sqlRECIPIENTS, strConnString );
SqlDataReader dtrRecipient = cmdSelect.ExecuteReader();
MailMessage objMailMessage;
while (dtrRecipient.Read())
{
// Create the Mail Message
objMailMessage = new MailMessage();
objMailMessage.From = "";
objMailMessage.To = dtrRecipient["Email"];
objMailMessage.Subject = dtrEmail["Subject"];
objMailMessage.Body = dtrEmail["Content"];
// Send the Mail Message
SmtpMail.Send( objMailMessage );
}
}
Thanks,
Andy
I am receiving the error when compiling the project, "cannot implicitly
convert type object to string".
The error points to this line of code and underlines the
dtrRecipient["Email"]: objMailMessage.To = dtrRecipient["Email"];
I'm not sure why I am getting this error. Below is the complete code I am
working with.
private void EmailEm()
{
string intSelectedEmail = ddlChooseEmail.SelectedValue.ToString();
string sqlGetEmail = "SELECT content, subject FROM tblContent WHERE id =
" + intSelectedEmail;
SqlCommand cmdGetEmail = new SqlCommand(sqlGetEmail, strConnString);
SqlDataReader dtrEmail = cmdGetEmail.ExecuteReader();
string intSelectedGroup = chkGroups.SelectedValue.ToString();
string sqlRECIPIENTS = "SELECT tblRecipients.Email AS Email FROM tblGR
INNER JOIN tblRecipients ON tblGR.RecipientID = tblRecipients.ID WHERE
tblGR.GroupID=" + intSelectedGroup;
SqlCommand cmdSelect = new SqlCommand( sqlRECIPIENTS, strConnString );
SqlDataReader dtrRecipient = cmdSelect.ExecuteReader();
MailMessage objMailMessage;
while (dtrRecipient.Read())
{
// Create the Mail Message
objMailMessage = new MailMessage();
objMailMessage.From = "";
objMailMessage.To = dtrRecipient["Email"];
objMailMessage.Subject = dtrEmail["Subject"];
objMailMessage.Body = dtrEmail["Content"];
// Send the Mail Message
SmtpMail.Send( objMailMessage );
}
}
Thanks,
Andy