Esempio n. 1
0
        public object ExecuteScalar(DbCommand cmd, DatabaseTransactions databaseTransaction)
        {
            object obj = null;

            try
            {
                cmd.Connection.Close();
                cmd.Connection  = databaseTransaction.DbConnection;
                cmd.Transaction = databaseTransaction.DbTransactions;
                obj             = cmd.ExecuteScalar();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (cmd.Connection.State == ConnectionState.Open)
                {
                    cmd.Connection.Close();
                    cmd.Dispose();
                }
            }
            return(obj);
        }
Esempio n. 2
0
        public DbDataReader ExecuteReader(DbCommand cmd, DatabaseTransactions databaseTransaction)
        {
            DbDataReader reader;

            try
            {
                cmd.Connection.Close();
                cmd.Connection  = databaseTransaction.DbConnection;
                cmd.Transaction = databaseTransaction.DbTransactions;
                reader          = cmd.ExecuteReader();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (cmd.Connection.State == ConnectionState.Open)
                {
                    cmd.Connection.Close();
                    cmd.Dispose();
                }
            }
            return(reader);
        }
Esempio n. 3
0
        public int ExecuteNonQuery(DbCommand cmd, DatabaseTransactions databaseTransaction)
        {
            int ret = -1;

            try
            {
                cmd.Connection.Close();
                cmd.Connection  = databaseTransaction.DbConnection;
                cmd.Transaction = databaseTransaction.DbTransactions;
                ret             = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (cmd.Connection.State == ConnectionState.Open)
                {
                    cmd.Connection.Close();
                    cmd.Dispose();
                }
            }
            return(ret);
        }
Esempio n. 4
0
        public DataTable ExecuteDataTable(DbCommand cmd, DatabaseTransactions databaseTransaction)
        {
            DataTable dataTable = new DataTable();

            try
            {
                cmd.Connection  = databaseTransaction.DbConnection;
                cmd.Transaction = databaseTransaction.DbTransactions;
                DbProviderFactory dbfactory     = DbProviderFactories.GetFactory(ProviderName);
                DbDataAdapter     dbDataAdapter = dbfactory.CreateDataAdapter();
                if (dbDataAdapter != null)
                {
                    dbDataAdapter.SelectCommand = cmd;
                    dbDataAdapter.Fill(dataTable);
                }
            }
            catch (Exception ex)
            {
                databaseTransaction.RollBack();
                throw ex;
            }
            finally
            {
                cmd.Parameters.Clear();
                if (cmd.Connection.State == ConnectionState.Open)
                {
                    cmd.Connection.Close();
                    cmd.Dispose();
                }
            }
            return(dataTable);
        }