ExecuteNonQuery return wrong value .NET 2.0

Posted on 2007-10-12
Last Modified: 2013-12-17
I have a stored procedure that deletes a single record (based on unique id)  When I run this from query analyzer it returns the out param as 1.   When I call this from .NET ExecuteNonQuery(cmd) it return a 19 which by definition is 19 records affected.  I have verified things by putting a new, single record in and deleting it via sql analyzer, then entering a single record and trying to delete it from ExecuteNonQuery.  It deletes but the return value is wrong and causes the rest of the app (which is expecint a 1) to cough.  Thougts?
Question by:mbowles
    LVL 16

    Accepted Solution

    ExecuteNonQuery returns the number of rows affected if you want to handle the return value you need to add a parameter to the Command with a Direction of ReturnValue

    Author Comment

    Turns out when I looked at the teamates sp it was usinga  return param value that needed to be capture and not a row affected count.  Switched to executescalar and all is well!

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now