0

I' so lost.... This is my stored proc:

@User_ID INT,
@Form_NAME NVARCHAR(25)
AS
BEGIN
    DECLARE @Count int = 0
    DECLARE @myReturnCode INT

    SELECT @Count = COUNT (tblForms.Form_Name)
        FROM  tblForms INNER JOIN
                       tblForms_Roles_MTM ON tblForms.Form_Id = tblForms_Roles_MTM.Form_Id INNER JOIN
                       tblRoles ON tblForms_Roles_MTM.Role_Id = tblRoles.Role_Id INNER JOIN
                       tblUsers_Roles_MTM ON tblRoles.Role_Id = tblUsers_Roles_MTM.Role_Id
        WHERE (tblUsers_Roles_MTM.User_Id = @User_ID AND tblForms.Form_Name = @Form_NAME)

    IF @Count = 0
        BEGIN SET @myReturnCode = 0 END
    ELSE
        BEGIN SET @myReturnCode = 1 END
    SELECT @myReturnCode as ReturnCode
END

In my code behind I call the procedure passing the 2 params and then :

...
con.Open();
int ReturnCode = (int)cmd.ExecuteScalar();
Response.Write(ReturnCode);

But myReturnCode is always 0.

When I execute the proc in SSMS is I see in "results" 2 values :

enter image description here

I guess that ExecuteScalar is returning the value of "Return Value".
So how do I get the value of "ReturnCode"?

I've been googling it for the past 36 hours. The answer is probably out there but....where? Couldn't find it.
Any hint will be greatly appreciated.
(Win-7 , SS-2014 , VS-2013)

gadi
  • 481
  • 3
  • 14
  • 32

1 Answers1

0

My sincere apologies.... Data in one of the tables was invalid. The procedure never found what it was meant to find, therefore it always returned 0. The stored procedure and the code are just fine. Fixing the data in that table solved my problem.

I am so ashamed.... Now how do I kill this question? It is just white noise in this forum.

gadi
  • 481
  • 3
  • 14
  • 32