Solved

ExecuteNonQuery returns double count

Posted on 2011-09-16
2
450 Views
Last Modified: 2012-08-14
If I run the following in VB.NET the return value of the record count is double the actual update in SQL Server.

cmd.CommandText = "update documents set IsVerified = 1 where  IsVerified= 0"
Dim ret As Integer = cmd.ExecuteNonQuery

The value of ret is double the actual records updated.

Additional Information.

In SQL Server when I run the update query the return messages are as follows.

(9 row(s) affected)

(9 row(s) affected)

It appears that the ExecuteNonQuery is returning the added value of Rows Affected reported by SQL Server.

If I run the select statement of records meeting the conditions I get 9 rows.
0
Comment
Question by:dbote
2 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 36548705
Do you have any triggers on the table as the return value will include any rows updated by the trigger as well as the initial update
0
 
LVL 1

Author Closing Comment

by:dbote
ID: 36548727
Yes, actually that is exactly the case.

It is not my database so I was not thinking about triggers.  It makes perfect sense though.

Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

13 Experts available now in Live!

Get 1:1 Help Now