Question : stored procedure always returns nonzero

I'm missing something really simple here...in testing a sql 2005 sp in asp.net 2.0 I whittled it down to this and "myresult" always returns -1, whereas I would expect 0 as success.   WHY?

objConn.Open()
Dim myresult As Integer = 0
Dim strSQL As String = "uspTEST"
Dim objCmd As New SqlCommand(strSQL, objConn)
objCmd.CommandType = CommandType.StoredProcedure
myresult = objCmd.ExecuteNonQuery()  *******************
===
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROC [dbo].[uspTEST]  
AS

DECLARE @saveerror int
SET @saveerror=0
select 'test'
set @saveerror=@@ERROR
return @saveerror

Answer : stored procedure always returns nonzero

>>Probably #1<<
Try it this way:

Dim cmd As SqlCommand = New SqlCommand("us_Test", cn)
cmd.CommandType = CommandType.StoredProcedure

Dim ReturnParam As SqlParameter = cmd.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
ReturnParam.Direction = ParameterDirection.ReturnValue

cmd.ExecuteNonQuery()

Dim myresult As Integer = ReturnParam.Value
Random Solutions  
 
programming4us programming4us