Ado calls the stored procedure to return multiple record sets (about the role of set nocount on in the Stored Procedure)

Source: Internet
Author: User

Recently, I answered several similar questions on csdn.

Http://community.csdn.net/Expert/TopicView.asp? Id = 4131244

Http://community.csdn.net/Expert/TopicView.asp? Id = 4156955

Generally, I asked why an error occurred while not returning a dataset or assigning a record set to the table control.

There are several reasons for the problem

1. It is unclear about the return mechanism of ADO. Connection. Execute. All records returned using this method are read-only and only forward cursor records.

Therefore, an error occurs when some table controls are assigned.

2. Set ncount on is not used in the stored procedure or improperly used.

Set nocount on is used to prevent SQL Server from returning the number of records affected by SQL statement operations,

Most SQL statements generate operation records, such as select, delete, update, insert ........

However, ADO treats the number of Operation Records returned by each operation as a record set. If more than one operation record is returned

The record set is returned.

However, ADO itself supports multiple record sets, and Rs. nextrecordset can be used to obtain any record set in a record set.

Therefore, you may obtain only the number of Operation records of a statement, rather than the record set to be returned.

Solution: place set nocount on at the beginning of the stored procedure

This is advantageous, so that SQL server does not affect the operation of each statement sent to the client, thus reducing network communication.

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.