On a webform button click, I have wired a SQL INSERT command along with the sending of an email. Right now I have:
try
{
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
message.SendMessage(to, from, subject, body);
Response.Redirect("~/complete.aspx");
}
If the INSERT command fails, it will go to the catch block, but I'm trying to avoid the insert command going through successfully and then the email failing.
How do I make sure that if the email doesn't get sent, the INSERT command will NOT occur?
Thanks!