ExecuteNonQuery

Method ExecuteNonQuery Method

Class :CA.Blocks.DataAccess.DataAccessCore

Namespace :CA.Blocks.DataAccess

Assembly : CA.Blocks.DataAccess.dll

Will execute a value sql query that does not return any results back to the client. This is typically Data modification statements such as insert , update or delete or catalog operations such as creating tables, indexes etc

Protected MethodExecuteNonQuery(System.Data.IDbCommand)

Will execute a value sql query that does not return any results back to the client. This is typically Data modification statements such as insert , update or delete or catalog operations such as creating tables, indexes etc

Parameters
NameTypeDescription
cmdSystem.Data.IDbCommand
Returns

System.Int32

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.

Example


            public int IncreasePriceBy10Percent()
            {
                /// This will Increase all Prices in the product table by 10%  and return the number of rows affected
                var cmd = CreateTextCommand("update products set price = price * 1.1");
                return ExecuteNonQuery(cmd);
            }
            

Remarks

Although the ExecuteNonQuery returns no rows, any output parameters or return values mapped to parameters are populated with data. This can useful when executing stored procedures.