I am trying to get a value from a stored procedure:

SET @RowCount = @@RowCount
	IF @RowCount = 1 BEGIN SET @Ret = 1 PRINT 'Insert a success' END
	IF isnull(@RowCount,0) = 0 BEGIN SET @Ret = 2 PRINT 'Insert a failure.. Terminating Proc...' RETURN END

I should be getting a 1 or 2, but keep getting a 0 with this code:

cmd.Parameters.Add("@Ret", SqlDbType.Int);
        cmd.Parameters["@Ret"].Direction = ParameterDirection.ReturnValue;
        conn.Open();
        int ReturnedVal=1;
        cmd.ExecuteNonQuery();
        ReturnedVal = (int)cmd.Parameters["@Ret"].Value;
        conn.Close();
        CountCheck.Text = Convert.ToString(ReturnedVal);

I would really like to get the printed statements, but will settle for anything at this point. :)

which version do you use asp.net 2.0?

Thanks for responding... I am using 2.0 and actually got what I needed from another forum, but if you have any other comments let me know... The initial issue was solved by adding the @Ret after the RETURN in the if statements.

Here is the solution:

SET @RowCount = @@RowCount
    IF @RowCount = 1 BEGIN SET @Ret = 1 PRINT 'Insert a success' END
    IF isnull(@RowCount,0) = 0 BEGIN SET @Ret = 2 PRINT 'Insert a failure.. Terminating Proc...' RETURN @Ret END
cmd.Parameters.Add("@Ret", SqlDbType.Int);
cmd.Parameters["@Ret"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int);
cmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
conn.Open();
int ReturnedVal=1;
cmd.ExecuteNonQuery();
ReturnedVal = (int)cmd.Parameters["@Ret"].Value;
int AlsoReturnedVal=(int)cmd.Parameters["@RETURN_VALUE"].Value;
conn.Close();
CountCheck.Text = Convert.ToString(ReturnedVal);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.