DbConnection.ExecuteNonQuery

public static class DbConnectionExtensions
{
    public static int ExecuteNonQuery(this DbConnection conn, string sql)
    {
        DbCommand cmd = conn.CreateCommand();
        cmd.CommandText = sql;

        return cmd.ExecuteNonQuery();
    }
}
Example:
DbConnection _db= new OleDbConnection(connectionString);
_db.Open();
int affected = _db.ExecuteNonQuery("delete from [Users]");

Description

Execute a SQL command directly on a DbConnection. Needless to say that the other ExecuteXXX methods can be implemented as well. Implementing the method at DbConnection level makes it available for SQLConnection, OleDbConnection, ...

Details

Double click on the code to select all.

 

;