S
Scott Natwick
Hi,
Is there a way to obtain the return code from a stored procedure?
Here is what I have so far. The procedure executes, but I'm not able to
find the return code from the procedure.
Thanks,
Scott
SqlConnection sqlConn = new SqlConnection(strDbConn);
SqlCommand sqlCmd = new SqlCommand("usp_proc_name", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter param1 = new SqlParameter("@PARAM_1", SqlDbType.VarChar, 100);
param1.Value = field1.Text;
sqlCmd.Parameters.Add(param1);
sqlCmd.Connection.Open();
SqlDataReader sqlReader =
sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
if (sqlReader.Read())
{
if (sqlReader.GetInt32(0) == 0)
{
// Procedure successul (expected)
}
else
{
// Procedure error occured (expected)
}
}
else
{
// Procedure error occured (expected)
** The debugger always lands here as I'm not doing something right **
}
CREATE PROCEDURE [dbo].[usp_proc_name]
@PARAM_1 varchar(100)
AS
INSERT INTO [dbo].
(
...
)
VALUES
(
...
)
SELECT @error_num = @@ERROR
RETURN @error_num
GO
Is there a way to obtain the return code from a stored procedure?
Here is what I have so far. The procedure executes, but I'm not able to
find the return code from the procedure.
Thanks,
Scott
SqlConnection sqlConn = new SqlConnection(strDbConn);
SqlCommand sqlCmd = new SqlCommand("usp_proc_name", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter param1 = new SqlParameter("@PARAM_1", SqlDbType.VarChar, 100);
param1.Value = field1.Text;
sqlCmd.Parameters.Add(param1);
sqlCmd.Connection.Open();
SqlDataReader sqlReader =
sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
if (sqlReader.Read())
{
if (sqlReader.GetInt32(0) == 0)
{
// Procedure successul (expected)
}
else
{
// Procedure error occured (expected)
}
}
else
{
// Procedure error occured (expected)
** The debugger always lands here as I'm not doing something right **
}
CREATE PROCEDURE [dbo].[usp_proc_name]
@PARAM_1 varchar(100)
AS
INSERT INTO [dbo].
(
...
)
VALUES
(
...
)
SELECT @error_num = @@ERROR
RETURN @error_num
GO