8000 Remarks for ExecuteNonQuery additional reasons to return -1 (#1876) · shdvr/dotnet-api-docs@bac390e · GitHub
[go: up one dir, main page]

Skip to content

Commit bac390e

Browse files
joelpaulaRon Petrusha
authored andcommitted
Remarks for ExecuteNonQuery additional reasons to return -1 (dotnet#1876)
* Remarks for ExecuteNonQuery additional reasons to return -1 Added a remark to ExecuteNonQuery for an additional reason for it to return -1 (the connection's NO COUNT is ON). * Applying the changes suggested by @divega Applying the changes suggested by @divega, to make it super clear how the NOCOUNT and other circumstances may affect the number of affected rows return by ExecuteNonQuery. * Update xml/System.Data.SqlClient/SqlCommand.xml Co-Authored-By: joelpaula <joelpaula@hotmail.com>
1 parent 126f205 commit bac390e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

xml/System.Data.SqlClient/SqlCommand.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,10 +2383,16 @@ public class A {
23832383
23842384
Although the <xref:System.Data.SqlClient.SqlCommand.ExecuteNonQuery%2A> returns no rows, any output parameters or return values mapped to parameters are populated with data.
23852385
2386-
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.
2387-
2388-
2389-
2386+
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.
2387+
2388+
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.
2389+
2390+
When SET NOCOUNT ON is set on the connection (before or as part of executing the command, or as part of a trigger initiated by the execution of the command) the rows affected by individual statements stop contributing to the count of rows affected that is returned by this method.
2391+
2392+
If no statements are detected that contribute to the count, the return value is -1. If a rollback occurs, the return value is also -1.
2393+
2394+
2395+
23902396
## Examples
23912397
The following example creates a <xref:System.Data.SqlClient.SqlCommand> and then executes it using <xref:System.Data.SqlClient.SqlCommand.ExecuteNonQuery%2A>. The example is passed a string that is a Transact-SQL statement (such as UPDATE, INSERT, or DELETE) and a string to use to connect to the data source.
23922398
@@ -3794,4 +3800,4 @@ For more information about asynchronous programming in the .NET Framework Data P
37943800
</Docs>
37953801
</Member>
37963802
</Members>
3797-
</Type>
3803+
</Type>

0 commit comments

Comments
 (0)
0