在SQL中使用TRY CATCH ,抓到错误时,想返回错误号,可是发现却无法获得RETURN的值,提示为NULL,不知道什么原因?????????
------------------------------------SQL-------
ALTER PROCEDURE testingOfReturn
@Val INT
AS
DECLARE @RESULT INT
SET @RESULT=0
BEGIN TRY
-- Generate a divide-by-zero error.
SELECT 1/0;
END TRY
BEGIN CATCH
--SELECT @RESULT=ERROR_NUMBER();
--SELECT @RESULT
RETURN @Val
END CATCH;
--RETURN @RESULT
GO
-------------------------------------------C#
SqlParameter[] para = new System.Data.SqlClient.SqlParameter[2];
para[0] = new SqlParameter("@Val", SqlDbType.Int);
para[0].Value = 2;
para[1] = new SqlParameter("@result", SqlDbType.Int);
para[1].Direction = ParameterDirection.ReturnValue;
using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "testingOfReturn", para))
{
Response.Write(para[1].Value.ToString());
}
----------------------------------------结果:para[1].Value=null