How can I get the stored procedure error message from code behind [Resolved]

Posted by Karthik2010_Mca under Interview Questions on 3/3/2013 | Points: 10 | Views : 2202 | Status : [Member] | Replies : 1
Hi,

How can I get the stored procedure error message from code behind (.cs file).

Thanks

Karthik


Responses

Posted by: Raj.Trivedi on: 3/3/2013 [Member] [MVP] Starter | Points: 50

Up
0
Down

Resolved
Hello Karthik2010_Mca

What kind of Error Message you are talking about, is it any error thrown by the stored procedure

then use try/catch block

check this

Over here i have a global string variable errdesc=0;

On button Click i am executing the procedure

protected void btnUpload_Click(object sender, EventArgs e)
{
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.

}
}

Hope this will help


Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Karthik2010_Mca, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response