none
Sp Return Type ExecuteNonQuery RRS feed

  • Question

  • sp result is 

    return @iresult

     

    from the code i am executing the query 

     

    ires = _command.ExecuteNonQuery();

     

    but what ever the sp is returning i am not able to see always getting -1 as return value

    Friday, May 7, 2010 7:21 PM

All replies

  • I'm assuming there isn't anything specific related to the Entity Framework here, since you haven't mentioned APIs that are part of the Entity Framework. Please let us know if there is something related to EF that isn't addressed by this post.

    ExecuteNonQuery returns how many rows were affected by the last operation in the stored procedure. You probably need to use ExecuteScalar instead, and you will need to call SELECT @iresult instead of RETURN @iresult.

    If you don't have any control over the stored procedure, you can retrieve the return value by using the techniques mentioned in this article. You will see how to do it in the section entitled "Using a Return Value."

    You should ask future questions about the SqlCommand APIs in the ADO.NET Managed Providers forum.

    Hope that helps,
    David


    Blog - http://blogs.rev-net.com/ddewinter/ Twitter - @ddewinter
    Saturday, May 8, 2010 12:54 AM
  • I tried with the reader also but it's always return -1

    if i explicitly set my return value  in the sp i am still getting -1

    Tuesday, May 11, 2010 8:22 PM