Click here to Skip to main content
15,895,829 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,


I'm displaying error message in my SP. Same error i want to display in page itself how to do that.

C#
command.Parameters.Add(new SqlParameter("@Insert_error", ParameterDirection.Output));
command.Parameters.Add(new SqlParameter("@Update_error", ParameterDirection.Output));


How to return this error messages.

can anyone help me ..

Thanks in advance...
Posted
Updated 4-Sep-12 21:18pm
v2

1 solution

In your SP set the output parameter to the error message in catch block. If any error occur. Set the error to output parameter. Otherwise return 0. Try this:
Stored Procedure:
SQL
SELECT @Insert_error = ERROR_MESSAGE()
SELECT @Update_error = ERROR_MESSAGE()

Now check the output parameter in front-end and show that.
C#
string retunvalue = (string)sqlcomm.Parameters["@Insert_error"].Value;
if(retunvalue == 0)
{
     //success
}
else
{
    //Show the error message which is there in your retunvalue variable 
}


Although, as I think, you don't need to do these all stuffs. Just handle SqlException and you'll get all your errors. Refer SqlException Class[^].


--Amit
 
Share this answer
 
v3
Comments
__TR__ 5-Sep-12 3:48am    
5+
_Amy 5-Sep-12 4:34am    
Thanks TR. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900