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

  • SEARCH
  • Home
  • 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 6581575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:10:14+00:00 2026-05-25T16:10:14+00:00

Running thru examples of Enterprise Library 5.0 and when I use ExecuteNonQuery to run

  • 0

Running thru examples of Enterprise Library 5.0 and when I use ExecuteNonQuery to run an update sproc, it returns 2. The update is based on ProductID, the table’s Primary Key (yes, I checked, and it is unique).

Here is the simple sproc:

ALTER PROCEDURE [dbo].[UpdateProductsTable]
     @ProductID int, 
     @ProductName varchar(50) = NULL, 
     @CategoryID int = NULL, 
     @UnitPrice money = NULL
AS
BEGIN
    UPDATE Products
    SET 
        ProductName = @ProductName, 
        CategoryID = @CategoryID, 
        UnitPrice = @UnitPrice
    WHERE ProductID = @ProductID
END

Executing this sp in SSMS shows “1 rows” in bottom right hand corner of the query results window, and a return value of 0 in the grid. Clicking on the messages tab shows

(1 row(s) affected)

(1 row(s) affected)

(1 row(s) affected)

not sure why I’m seeing this 3 times here, but I don’t believe that is the issue.

Here is the code calling the sp:

public static void Exec_Update_Query()
        //updates a column of a single row, checks that the update succeeded, and then update it again to return it to the original value 
        {
            string oldName = "Chai";
            string newName = "Chai Tea";

            SqlDatabase defaultDB = EnterpriseLibraryContainer.Current.GetInstance<Database>() as SqlDatabase;

            // Create command to execute the stored procedure and add the parameters.
            DbCommand cmd = defaultDB.GetStoredProcCommand("UpdateProductsTable");
            defaultDB.AddInParameter(cmd, "ProductID", DbType.Int32, 1);
            defaultDB.AddInParameter(cmd, "ProductName", DbType.String, newName);
            defaultDB.AddInParameter(cmd, "CategoryID", DbType.Int32, 1);
            defaultDB.AddInParameter(cmd, "UnitPrice", DbType.Currency, 18);

            // Execute the query and check if one row was updated.
            int i = defaultDB.ExecuteNonQuery(cmd);
            if (i == 1)
            {
              // Update succeeded.
            }
            else
            {
                Console.WriteLine("ERROR: Could not update just one row.");
            }

            // Change the value of the second parameter
            defaultDB.SetParameterValue(cmd, "ProductName", oldName);

            // Execute query and check if one row was updated
            if (defaultDB.ExecuteNonQuery(cmd) == 1)
            {
              // Update succeeded.
            }
            else
            {
                Console.WriteLine("ERROR: Could not update just one row.");
            }
        }

I’m using int i to view the return value from the method and it returns 2. Any ideas why this would be? This is Enterprise Libarary 5.0 in VS2010 running against SQL 2005. Pretty straightforward but perplexing.

  • 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-05-25T16:10:15+00:00Added an answer on May 25, 2026 at 4:10 pm

    If I recall correctly, the result of any triggers that fire as a result of your commands will also be included in the returned row count. Most likely, this is your issue.

    EDIT: Documentation

    From MSDN SqlCommand.ExecuteNonQuery:

    When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running Python 3.2 on Win XP. I run a python script thru a
I am trying out Silverlight's Isolated Storage feature. Currently running Silverlight thru ASP.NET page.
When running the following script: on run tell application Safari set allWins to every
I'm getting an error when running the following code thru an ASP/ C# .NET
I'm trying to use rdebug with emacs and cygwin and I'm running into trouble.
I know that running applications in DEBUG (build configuration) thru the visual studio adds
I am having issues with regards to running my ASP.NET MVC application thru my
I am trying to use the calendar component from Myfaces Tomahawk. I am running
Is it possible to use external activation on sql express without going thru sql
Why is it that when I run ANALYZE TABLE table_name_here The MySQL server starts

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.