I have an event handler that is failing with an SqlException '{"Procedure or function 'SetClientEmail' expects parameter '@OldEmailAddress', which was not supplied."}'
However, the code for the SqlParameter '@OldEmailAddress' is no different than that for the other SqlParameters I am using, both for this command and for others I have been able to run successfully.
protected void ChangeAddress(object sender, EventArgs e)
{
string newEmail = NewEmailTextBox.Text;
if (newEmail == ConfirmTextBox.Text)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ServicePro"].ConnectionString);
SqlCommand command = new SqlCommand("SetClientEmail", conn);
command.CommandType = CommandType.StoredProcedure;
SqlParameter key = new SqlParameter("@AccountKey", SqlDbType.Int);
key.Value = accountKey;
command.Parameters.Add(key);
SqlParameter oldEmailAddress = new SqlParameter("@OldEmailAddress", SqlDbType.Text);
oldEmailAddress.Value = email;
command.Parameters.Add(oldEmailAddress);
SqlParameter newEmailAddress = new SqlParameter("@NewEmailAddress", SqlDbType.Text);
newEmailAddress.Value = newEmail;
command.Parameters.Add(newEmailAddress);
conn.Open();
command.ExecuteNonQuery();
conn.Close();
Response.Redirect("~/Start.aspx");
}
else
{
ConfirmTextBox.Text = "";
Validate();
}
}
I can only conclude that I am missing something important, but I cannot determine what. Any advice on this matter would be appreciated.