如何在页面本身中返回SP错误消息 [英] How to return SP error message in page itself

查看:59
本文介绍了如何在页面本身中返回SP错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在我的SP中显示错误消息.我想在页面本身中显示相同的错误该怎么做.

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...

推荐答案

在您的SP中,将输出参数设置为catch块中的错误消息.如果发生任何错误.将错误设置为输出参数.否则返回0.尝试以下操作:
存储过程:
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 
}



虽然,按照我的想法,您不需要做所有这些事情.只要处理SqlException,您就会得到所有错误.引用 SqlException类 [



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


这篇关于如何在页面本身中返回SP错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆