Click here to Skip to main content
11,575,882 members (54,105 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
Hi,


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
Edited 4-Sep-12 21:18pm
v2

1 solution

Rate this: bad
good
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)
{
     //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
  Permalink  
v3
Comments
__TR__ at 5-Sep-12 3:48am
   
5+
_Amy at 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
0 Sergey Alexandrovich Kryukov 390
1 Dave Kreskowiak 204
2 F-ES Sitecore 135
3 OriginalGriff 125
4 Abhinav S 98
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 600
2 Abhinav S 438
3 F-ES Sitecore 400
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2015
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