Catching Error from Stored Proc in TRY/Catch Block

Raj.Trivedi
Posted by Raj.Trivedi under C# category on | Points: 40 | Views : 1488
try
{
SqlConnection con = new SqlConnection(strconn);
con.Open();
SqlCommand cmd = new SqlCommand("InsertPowerPoint",con); // Stored Proc Name
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PowerPointName",SqlDbType.VarChar).Value = filename;
cmd.Parameters.AddWithValue("@PowerPointPath",SqlDbType.VarChar).Value = pptpath;
cmd.ExecuteNonQuery();

xErr.Text = "Uploaded Successfully"; // If No Error then Uploaded Successfully
xErr.Visible = true;
FillGrid();
}
catch (Exception ex)
{
errdesc = ex.Message;
xErr.Text = errdesc; //any error from SP then It will show in Label after catching the error in exception.

}

Comments or Responses

Login to post response