Click here to Skip to main content
12,884,509 members (33,318 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0

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

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 4-Sep-12 21:15pm
Updated 4-Sep-12 21:18pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:
SELECT @Insert_error = ERROR_MESSAGE()
SELECT @Update_error = ERROR_MESSAGE()

Now check the output parameter in front-end and show that.
string retunvalue = (string)sqlcomm.Parameters["@Insert_error"].Value;
if(retunvalue == 0)
    //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[^].

__TR__ 5-Sep-12 3:48am
_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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100