Without any knowledge of the Sybase provider, the likely answer is that ExecuteNonQuery returns the sum of the "Number of rows affected" returned by the SQL statement. In SQL Server, @@ ROWCOUNT returns the number of rows affected by the last statement.
I found this comment in the SqlCommand.cs source in the return value of ExecuteNonQuery, but did not actually check it:
// sql reader will pull this value out for each NextResult call. It is not cumulative // _rowsAffected is cumulative for ExecuteNonQuery across all rpc batches internal int _rowsAffected = -1; // rows affected by the command
In SQL Server, you can use SET NOCOUNT in stored procedures to control the number of count messages returned. ExecuteNonQuery returns -1 if messages are not returned by setting SET NOCOUNT ON at the beginning.
SET and RETURN do not send messages to the same output stream as list messages, but PRINT. The printed lines should not affect the return value of the integer value of ExecuteNonQuery, but I cannot say.
The point is, it's better to use T-SQL output parameters to compute interesting strings than relying on the return value of ExecuteNonQuery. An alternative to the output parameters is to use the SELECT and ExecuteScalar result set.
see also
Overriding rows affected in SQL Server using ExecuteNonQuery?
source share