Bongekilez
Bongekilez

Reputation: 1

Using stored procedure to send an email from a C# code (correlating C# code into a stored procedure error)

protected void btnSend_Click(object sender, EventArgs e)
{
    try
    {
        var stringConnection = ConfigurationManager.AppSettings["ConnectionString"];
        var myconnection = new SqlConnection(stringConnection);
        myconnection.Open();

        var myCommand = new SqlCommand("sp_myprocedure", myconnection)
        {
            CommandType = CommandType.StoredProcedure,
            Connection = myconnection,
            //CommandText = "sp_myprocedure"
        };

        myconnection.Close();
        myconnection.Dispose();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

My stored procedure works perfectly and sends an email to the recipients, but when I combine it with the C# code it doesn't work. The program doesn't run at all. I am using a web based application of C#.

All I need to do is to send an email to a user. Can I please get help in correlating C# code into MySQL code.

Upvotes: 0

Views: 570

Answers (1)

stuartd
stuartd

Reputation: 73313

You need to actually execute the command:

myCommand.ExecuteNonQuery();

Upvotes: 2

Related Questions