[dba-VB] C# - return value for stored procedures

jwcolby jwcolby at colbyconsulting.com
Mon Nov 30 11:44:39 CST 2009


While I am getting back values in my "output" parameters for the SPs, I am getting a constant -1 for 
the return value.

In the stored procedure I have tried just using

RETURN 1234

and also creating an int variable, setting that to 1234 and returning that.

declare @Ret int	
	select @ret = 1234
     	RETURN @ret

In all cases I get a -1 value which leads me to believe that the problem is on the C# side of things.

My c# code looks like:

try
{
	if (sCmd.Connection.State != ConnectionState.Open)
         	sCmd.Connection.Open();
	int retValue = sCmd.ExecuteNonQuery();
	return retValue;
}
catch (SqlException sqlEx)
{
	throw sqlEx;
}

I am not throwing an error, the SP executes, but retValue is always -1.

Any ideas?  Do I need to add a SqlParameter to the Parameters collection for the return value?

-- 
John W. Colby
www.ColbyConsulting.com



More information about the dba-VB mailing list