C # ExecuteNonQuery () return value-1

Source: Internet
Author: User

This is before I encountered a problem, found on the Internet to find a solution, then copied to the TXT document, today to organize notes and see, posted out, easy to consult later. The author of the original did not remember ~ ~

When querying for data in a table, it is not correct to use ExecuteNonQuery () to determine whether the value is greater than the limit of the data being determined.

The SqlCommand.ExecuteNonQuery method executes Transact-SQL statements on the connection and returns the number of rows affected.

Note: You can use ExecuteNonQuery to perform directory operations, such as querying the structure of a database or creating database objects such as tables, or by executing an UPDATE, INSERT, or DELETE statement to change data in a database without using a dataset.

Although ExecuteNonQuery does not return any rows, any output parameters or return values that are mapped to parameters are populated with data. For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is-1. If a rollback occurs, the return value is also-1

That is, if the statement that is not the Update,insert,delete operation data record, the return value is-1, so the SELECT statement is not suitable for the ExecuteNonQuery () method

(GO) C # ExecuteNonQuery () return value-1

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.