Recently, I was busy with a project. When querying whether data exists in a table, I used executenonquery () and determined whether the value was greater than 0 to determine whether the data exists or not. The results are inconsistent with what I imagined. I found that the result returned after the execution was-1, which I did not understand very well. I checked the information, as shown below: sqlcommand. executenonquery method executes a Transact-SQL statement on the connection and returns the number of affected rows. Note: executenonquery can be used to perform directory operations (such as querying the database structure or creating database objects such as tables), or by executing update, insert, or delete statements, change the data in the database without using dataset. Although executenonquery does not return any rows, any output parameters or return values mapped to parameters are filled with data. For update, insert, and delete statements, the returned 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 returned value is-1. The SELECT statement is not suitable for the executenonquery () method. It turns out to be so stupid. The method is wrong! I recorded it specially and hoped that my friends would not make similar mistakes.
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