public static int Exec( this SqlConnection connection, SqlTransaction transaction, CommandType commandType, string sqlText, IEnumerable <SqlParameter> parmList) { using (SqlCommand command = new SqlCommand(sqlText, connection)) { command.CommandType = commandType; if (transaction.IsNotNull()) { command.Transaction = transaction; } if (parmList.IsNotNull()) { foreach (SqlParameter parm in parmList) { command.Parameters.Add(parm); } } int returnValue = command.ExecuteNonQuery(); command.Parameters.Clear(); return(returnValue); } }
public static T ExecScalar <T>( this SqlConnection connection, SqlTransaction transaction, CommandType commandType, string sqlText, IEnumerable <SqlParameter> parmList, T defaultValue) { using (SqlCommand command = new SqlCommand(sqlText, connection)) { command.CommandType = commandType; if (transaction.IsNotNull()) { command.Transaction = transaction; } if (parmList.IsNotNull()) { foreach (SqlParameter parm in parmList) { command.Parameters.Add(parm); } } T returnValue = SObject.DbValueAs <T>(command.ExecuteScalar(), defaultValue); command.Parameters.Clear(); return(returnValue); } }
/// <summary> /// Test if the database has a pending transaction. /// </summary> /// <returns>True if there is a pending transaction.</returns> public Boolean HasPendingTransaction() { return(_transaction.IsNotNull()); }