Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:57:40+00:00 2026-06-01T20:57:40+00:00

UPDATE : my code is behaving as expected by there was a typo in

  • 0

UPDATE: my code is behaving as expected by there was a typo in the stored procedure that was the reason it was failing.


I can’t seem to figure out why or how to fix this because I am not getting any errors what I am getting is the return value is 0 which means fail.

Here is my .net code:

SqlParameter returnValue= new SqlParameter("returnValue", SqlDbType.Int);
returnValue.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(returnValue);

cmd.ExecuteNonQuery();

result = Convert.ToInt32(returnValue.Value); //1 success and 0 failed 

My stored procedure:

CREATE PROCEDURE EmployeeUpdate
    @employee_id BIGINT,
    @name nvarchar(250)
AS
BEGIN 
    SET NOCOUNT ON 

    DECLARE @Result int  
    SET @Result = 0  

    UPDATE Employee
    SET name = @name 
    WHERE employee_id = @employee_id                   

    IF (@@rowcount = 1) 
    BEGIN
        SET @Result = 1       
    END

    SET NOCOUNT OFF

    RETURN @Result 
END

So if I just execute the stored procedure from SQL Server Management Studio, it does update my row successfully without any error

EXEC EmployeeUpdate 34,'John John'

Return Value = 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:57:42+00:00Added an answer on June 1, 2026 at 8:57 pm

    I would suggest to remove returnValue parameter altogether and just use the return value of ExecuteNonQuery() method instead:

    int rowsAffected = cmd.ExecuteNonQuery();
    
    result = rowsAffected == 1 ? 1 : 0;
    

    Stored procedure:

    CREATE PROCEDURE EmployeeUpdate
           @employee_id BIGINT,
           @name nvarchar(250)
    AS
    BEGIN 
          UPDATE Employee
          SET  name = @name 
          WHERE  employee_id = @employee_id                   
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that I regularly update the code to. I keep it
I've got a C# web application which I can't easily update the code of.
I can update code correctly, but cannot commit code. I get the following error
I am trying to update code via Linq, but I am getting this error:
I am using following steps to update code on server after login to server:
suppose you update your code to revision 10 which is broken. You want to
I have the following code: UPDATE myTable SET Col1 = @Value However, I have
Here is my upsert code: UPDATE LastTicket SET LastTicketNumber=LastTicketNumber+1 OUTPUT INSERTED.LastTicketNumber WHERE CategoryId='1'; IF
You've pushed a code update to a daemontools service and want to restart it
UPDATE: Edited javascript code. It's only slightly off now in some columns. Maybe a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.