在上一篇文章中已经分析了AdoHelper的部分代码,接下来将继续分析剩余的部分代码,这里分析ExecuteNonQuery方法的实现,代码块1-1:
// <summary> //通过提供的参数,执行无结果集的数据库操作命令 // 并返回执行数据库操作所影响的行数。 // </summary> // <param name="connectionString">数据库连接字符串</param> // <param name="commandType">执行命令的类型(存储过程或T-SQL,等等)</param> // <param name="commandText">存储过程名称或者T-SQL命令行<</param> // <param name="commandParameters">执行命令所需的参数数组</param> // <returns>返回通过执行命令所影响的行数</returns> public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params IDbDataParameter[] commandParameters) { IDbCommand cmd = DbFactory.CreateDbCommand(); using (IDbConnection conn = DbFactory.CreateDbConnection(connectionString)) { PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters); int val = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); return val; } } //============================================================================================= public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText) { IDbCommand cmd = DbFactory.CreateDbCommand(); using (IDbConnection conn = DbFactory.CreateDbConnection(connectionString)) { PrepareCommand(cmd, conn, null, cmdType, cmdText, null); int val = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); return val; } } //============================================================================================= public static int ExecuteNonQuery(IDbConnection connection, CommandType cmdType, string cmdText, params IDbDataParameter[] commandParameters) { IDbCommand cmd = DbFactory.CreateDbCommand(); PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters); int val = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); return val; } //============================================================================================= public static int ExecuteNonQuery(IDbConnection connection, CommandType cmdType, string cmdText) { IDbCommand cmd = DbFactory.CreateDbCommand(); PrepareCommand(cmd, connection, null, cmdType, cmdText, null); int val = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); return val; } //============================================================================================= // <summary> //通过提供的参数,执行无结果集返回的数据库操作命令 //并返回执行数据库操作所影响的行数。 // </summary> // <remarks> // e.g.: // int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24)); // </remarks> // <param name="trans">sql事务对象</param> // <param name="commandType">执行命令的类型(存储过程或T-SQL,等等)</param> // < |