예제 #1
0
        protected IDataReader ExecutarReader(string command, CommandType commandType, int timeout = 30)
        {
            try
            {
                Conexao = MyDatabase.CreateConnection();
                Conexao.Open();

                MyCommand = (commandType == CommandType.StoredProcedure) ? MyDatabase.GetStoredProcCommand(command)
                                                                         : MyDatabase.GetSqlStringCommand(command);

                MyCommand.CommandTimeout = timeout;

                VincularParametros();

                return(MyDatabase.ExecuteReader(MyCommand));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                if (MyCommand != null)
                {
                    MyCommand.Dispose();
                }
                if (Conexao != null)
                {
                    Conexao.Dispose();
                    Conexao.Close();
                }
            }
        }
예제 #2
0
        protected object ExecutarScalar(string command)
        {
            try
            {
                Conexao = MyDatabase.CreateConnection();
                Conexao.Open();

                if (UsarTransacao)
                {
                    Transacao = Conexao.BeginTransaction();
                }

                MyCommand = MyDatabase.GetStoredProcCommand(command);
                VincularParametros();

                MyCommand.Connection = Conexao;

                var retorno = MyCommand.ExecuteScalar();

                if (UsarTransacao)
                {
                    Transacao.Commit();
                }

                return(retorno);
            }
            catch (Exception e)
            {
                if (UsarTransacao)
                {
                    Transacao.Rollback();
                }

                if (!UsarException)
                {
                    return(null);
                }


                throw new Exception(e.Message);
            }
            finally
            {
                if (MyCommand != null)
                {
                    MyCommand.Dispose();
                }
                if (Conexao != null)
                {
                    Conexao.Dispose();
                    Conexao.Close();
                }
            }
        }
예제 #3
0
        protected void Executar(string command, CommandType commandType)
        {
            try
            {
                Conexao = MyDatabase.CreateConnection();
                Conexao.Open();

                if (UsarTransacao)
                {
                    Transacao = Conexao.BeginTransaction();
                }

                MyCommand = (commandType == CommandType.StoredProcedure) ? MyDatabase.GetStoredProcCommand(command)
                                                                         : MyDatabase.GetSqlStringCommand(command);
                VincularParametros();

                MyCommand.Connection = Conexao;

                MyCommand.ExecuteNonQuery();

                if (UsarTransacao)
                {
                    Transacao.Commit();
                }
            }

            catch (SqlException sq)
            {
                if (UsarTransacao)
                {
                    Transacao.Rollback();
                }
                throw new Exception(sq.Message);
            }
            finally
            {
                if (MyCommand != null)
                {
                    MyCommand.Dispose();
                }
                if (Conexao != null)
                {
                    Conexao.Dispose();
                    Conexao.Close();
                }
            }
        }