Sqlcommand. executenonquery () the number of affected rows is not returned when the stored procedure is executed.

Source: Internet
Author: User

I encountered a problem that I rarely encountered today. The record is as follows:

In the database, there is a stored procedure sp_createorupdatexxx that executes the insert or update (already exists) operation,

InProgramWhen SQL command. executenonquery () is executed, no affected rows are returned.

Check the stored procedure and find thatCodeThe first line has an additional SQL statement:Set nocount on;

After the code is deleted, the number of affected lines is returned.

 

MATERIALS:

WhenSet nocountIs OnNo count is returned (indicating the number of rows affected by the transct-SQL statement ).

If some statements contained in the stored procedure do not return a large amount of actual data, the setting can significantly improve the performance because it greatly reduces network traffic.

WhenSet nocountIs OffReturn count.

Even ifWhenSet nocountIs On,Also update the @ rowcount function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.