Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExecuteNonQuery returns what int value [closed]

Tags:

c#

asp.net

What values ExecuteNonQuery returns if update, insert, delete are success, at the same time when they were failed?

like image 998
Ravi Kiran Ayinampudi Avatar asked Feb 06 '14 11:02

Ravi Kiran Ayinampudi


2 Answers

ExecuteNonQuery returns the number of rows affected.

ExecuteNonQuery

 For UPDATE, INSERT, and DELETE statements, the return value is the number of 
rows affected by the command.
like image 175
Nagaraj S Avatar answered Nov 14 '22 22:11

Nagaraj S


You might find the following reference material handy, SqlCommand.ExecuteNonQuery Method .

To quote directly:

Executes a Transact-SQL statement against the connection and returns the number of rows affected.

So...

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

So either the number of rows affected by the command(s) or -1.

like image 26
Matt Woodward Avatar answered Nov 14 '22 21:11

Matt Woodward