/// <summary> /// Execute a TurboDBCommand (that returns no resultset) against the specified TurboDBTransaction /// using the provided parameters. /// </summary> /// <remarks> /// e.g.: /// int result = ExecuteNonQuery(trans, CommandType.Text, "Select * from TableTransaction where ProdId=?", new TurboDBParameter("@prodid", 24)); /// </remarks> /// <param name="transaction">A valid TurboDBTransaction</param> /// <param name="commandType">The CommandType (TableDirect, Text)</param> /// <param name="commandText">The T-SQL command</param> /// <param name="commandParameters">An array of TurboDBParamters used to execute the command</param> /// <returns>An int representing the number of rows affected by the command</returns> public static int ExecuteNonQuery(TurboDBTransaction transaction, CommandType commandType, string commandText, params TurboDBParameter[] commandParameters) { if( transaction == null ) throw new ArgumentNullException( "transaction" ); if( transaction != null && transaction.Connection == null ) throw new ArgumentException( "The transaction was rollbacked or commited, please provide an open transaction.", "transaction" ); // Create a command and prepare it for execution TurboDBCommand cmd = new TurboDBCommand(); bool mustCloseConnection = false; PrepareCommand(cmd, (TurboDBConnection)transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection ); // Finally, execute the command int retval = cmd.ExecuteNonQuery(); // Detach the TurboDBParameters from the command object, so they can be used again cmd.Parameters.Clear(); return retval; }
/// <summary> /// Execute a TurboDBCommand (that returns no resultset) against the specified TurboDBConnection /// using the provided parameters. /// </summary> /// <remarks> /// e.g.: /// int result = ExecuteNonQuery(conn, CommandType.Text, "Update TableTransaction set OrderAmount = 500 where ProdId=?", new TurboDBParameter("@prodid", 24)); /// </remarks> /// <param name="connection">A valid TurboDBConnection</param> /// <param name="commandType">The CommandType (TableDirect, Text)</param> /// <param name="commandText">The T-SQL command</param> /// <param name="commandParameters">An array of TurboDBParamters used to execute the command</param> /// <returns>An int representing the number of rows affected by the command</returns> public static int ExecuteNonQuery(TurboDBConnection connection, CommandType commandType, string commandText, params TurboDBParameter[] commandParameters) { if( connection == null ) throw new ArgumentNullException( "connection" ); // Create a command and prepare it for execution TurboDBCommand cmd = new TurboDBCommand(); bool mustCloseConnection = false; PrepareCommand(cmd, connection, (TurboDBTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection ); // Finally, execute the command int retval = cmd.ExecuteNonQuery(); // Detach the TurboDBParameters from the command object, so they can be used again cmd.Parameters.Clear(); if( mustCloseConnection ) connection.Close(); return retval; }