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
- Author: Gaston Verelst
- Submitted on: 7-2-2011 11:39:21
- Language: C#
- Type: System.Data.Common.DbConnection
- Views: 3779
Double click on the code to select all.