简体   繁体   English

我们如何使用sqlcommand在VB.net代码中处理MSSQL引发错误?

[英]How can we handle MSSQL raiseerror in VB.net code behind using sqlcommand?

I have written one store procedure which raise error on same specific condition. 我编写了一个存储过程,在相同的特定条件下会引发错误。 when i call this store procedure using vb.net code using sqlcommand I m not able to catch RAISEERROR 当我使用sqlcommand使用vb.net代码调用此存储过程时,我无法捕获RAISEERROR

Store Procedure 存放程序

Create sp_UPDATE
as 
begin


    IF @QTY > @ReqAlloQty
    BEGIN
         RAISERROR('Product Quantity should not be more than Required qty.',16,1)        
         goto EXITWITHERROR  
    END             

end

VB.NET VB.NET

 Try
    m_commDBcommand.ExecuteNonQuery()
 Catch ex As Exception
 Finally
 End Try

exception is not raised when store procedure condition is matched. 匹配存储过程条件时,不会引发异常。

Any help will be appreciated 任何帮助将不胜感激

Add a return statement after raiserror: 在rarrrror之后添加一个返回语句:

RAISERROR('Product Quantity should not be more than Required qty.',16,1);
RETURN;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM