Exemplo n.º 1
0
        public int ExecuteNonQuery(DbCommand scdCommand)
        {
            try
            {
                DbConnection Conn = Conexao.abrirConexao(ConnectionStringName);
                scdCommand.Connection = Conn;

                return(scdCommand.ExecuteNonQuery());
            }
            catch (DbException ex)
            {
                throw ex;
                ////TrataException.SetError(ex);
                //int numeroErro = LogEventError.Write(ex.Message);
                //throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
            }
            catch (Exception ex2)
            {
                string x = ex2.Message;
                throw new Exception(ex2.Message, ex2);
            }
            finally
            {
                Conexao.fecharConexao(scdCommand.Connection);
                scdCommand.Dispose();
            }
        }
Exemplo n.º 2
0
        public DataSet ExecuteDbDataSet(DbCommand scdCommand)
        {
            DbConnection Conn = Conexao.abrirConexao(ConnectionStringName);

            scdCommand.Connection = Conn;

            DbDataAdapter daAdapter = Conexao.obterDataAdapter(scdCommand.Connection);

            try
            {
                DataSet dsDados = new DataSet();
                daAdapter.SelectCommand = scdCommand;
                daAdapter.Fill(dsDados);

                daAdapter = null;
                return(dsDados);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                daAdapter.Dispose();
                Conexao.fecharConexao(scdCommand.Connection);
                scdCommand.Dispose();
            }
        }
Exemplo n.º 3
0
        public DataSet ExecuteDbDataSet(DbCommand scdCommand)
        {
            DbConnection Conn = Conexao.abrirConexao();

            scdCommand.Connection = Conn;

            DbDataAdapter daAdapter = Conexao.obterDataAdapter(scdCommand.Connection);

            try
            {
                DataSet dsDados = new DataSet();
                daAdapter.SelectCommand = scdCommand;
                daAdapter.Fill(dsDados);

                daAdapter = null;
                return(dsDados);
            }
            catch (Exception ex)
            {
                int numeroErro = LogEventError.Write(ex.Message);
                throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
            }
            finally
            {
                daAdapter.Dispose();
                Conexao.fecharConexao(scdCommand.Connection);
                scdCommand.Dispose();
            }
        }
Exemplo n.º 4
0
        public object ExecuteScalar(DbCommand scdCommand)
        {
            try
            {
                DbConnection Conn = Conexao.abrirConexao(ConnectionStringName);
                scdCommand.Connection = Conn;

                return(scdCommand.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Conexao.fecharConexao(scdCommand.Connection);
                scdCommand.Dispose();
            }
        }
Exemplo n.º 5
0
        public object ExecuteNonQuery(DbCommand scdCommand, bool bolHasReturnValue)
        {
            try
            {
                DbConnection Conn = Conexao.abrirConexao(ConnectionStringName);
                scdCommand.Connection = Conn;

                return(scdCommand.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Conexao.fecharConexao(scdCommand.Connection);
                scdCommand.Dispose();
            }
        }
Exemplo n.º 6
0
 public int InserirOracle(DbCommand scdCommand)
 {
     try
     {
         DbConnection Conn = Conexao.abrirConexao(ConnectionStringName);
         scdCommand.Connection = Conn;
         this.AddOutParameter(scdCommand, "IDENTITY", DbType.Int32, 4);
         scdCommand.ExecuteNonQuery();
         return((int)scdCommand.Parameters["IDENTITY"].Value);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         Conexao.fecharConexao(scdCommand.Connection);
         scdCommand.Dispose();
     }
 }
Exemplo n.º 7
0
        public object ExecuteScalar(DbCommand scdCommand)
        {
            try
            {
                DbConnection Conn = Conexao.abrirConexao();
                scdCommand.Connection = Conn;

                return(scdCommand.ExecuteScalar());
            }
            catch (Exception ex)
            {
                int numeroErro = LogEventError.Write(ex.Message);
                throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
            }
            finally
            {
                Conexao.fecharConexao(scdCommand.Connection);
                scdCommand.Dispose();
            }
        }
Exemplo n.º 8
0
 public int InserirOracle(DbCommand scdCommand)
 {
     try
     {
         DbConnection Conn = Conexao.abrirConexao();
         scdCommand.Connection = Conn;
         this.AddOutParameter(scdCommand, "IDENTITY", DbType.Int32, 4);
         scdCommand.ExecuteNonQuery();
         return((int)scdCommand.Parameters["IDENTITY"].Value);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
     finally
     {
         Conexao.fecharConexao(scdCommand.Connection);
         scdCommand.Dispose();
     }
 }
Exemplo n.º 9
0
 public DataTable ExecuteOracleDataTableWithoutCursor(DbCommand scdCommand)
 {
     try
     {
         OracleCommand    cm = (OracleCommand)scdCommand;
         OracleConnection cn = (OracleConnection)Conexao.abrirConexao(ConnectionStringName);
         cm.Connection = cn;
         //cm.Parameters.Add(CursorRetorno, OracleType.Cursor).Direction = ParameterDirection.Output;
         OracleDataReader dr = cm.ExecuteReader(CommandBehavior.CloseConnection);
         DataTable        dt = new DataTable();
         dt.Load(dr);
         return(dt);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         Conexao.fecharConexao(scdCommand.Connection);
         scdCommand.Dispose();
     }
 }
Exemplo n.º 10
0
 public DataTable ExecuteOracleDataTable(DbCommand scdCommand)
 {
     try
     {
         OracleCommand    cm = (OracleCommand)scdCommand;
         OracleConnection cn = (OracleConnection)Conexao.abrirConexao();
         cm.Connection = cn;
         cm.Parameters.Add(CursorRetorno, OracleType.Cursor).Direction = ParameterDirection.Output;
         OracleDataReader dr = cm.ExecuteReader(CommandBehavior.CloseConnection);
         DataTable        dt = new DataTable();
         dt.Load(dr);
         return(dt);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception(string.Format("Ocorreu um erro número:{0}. Descrição: {1}", numeroErro, ex.Message));
     }
     finally
     {
         Conexao.fecharConexao(scdCommand.Connection);
         scdCommand.Dispose();
     }
 }