Beispiel #1
0
        public int ContarUsuarios()
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "SELECT COUNT(*) FROM CONTATOS";
            return((int)comando.ExecuteScalar());
        }
        public void Excluir(int id)
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "DELETE FROM CONTATOS WHERE ID = @id";
            comando.Parameters.Add(new SqlParameter("@id", id));
            comando.ExecuteNonQuery();
        }
        //Excluir Contato
        public void Excluir(int id)
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "DELETE FROM tbl_cadastro"; //WHERE id_aluno = @id";
            //comando.Parameters.Add(new MySqlParameter("@id", id));

            comando.ExecuteNonQuery();
        }
        public void Inserir(Contato contato)
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "INSERT INTO CONTATOS(NOME, EMAIL, TELEFONE) VALUES (@nome, @email, @telefone)";
            comando.Parameters.Add(new SqlParameter("@nome", contato.Nome));
            comando.Parameters.Add(new SqlParameter("@email", contato.Email));
            comando.Parameters.Add(new SqlParameter("@telefone", contato.Telefone));
            comando.ExecuteNonQuery();
        }
Beispiel #5
0
        public void Inserir(Contato contato)
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "INSERT INTO CONTATOS (NOME, EMAIL, TELEFONE) VALUES (@NOME, @EMAIL, @TELEFONE)"; // INFO SERAO INSERIDAS NA CLASSE CONTATO SEGUNDO O PARAMENTRO CONTATO.

            comando.Parameters.Add(DAOUtils.GetParameter("@nome", contato.Nome));
            comando.Parameters.Add(DAOUtils.GetParameter("@email", contato.Email));
            comando.Parameters.Add(DAOUtils.GetParameter("@telefone", contato.Telefone));
            comando.ExecuteNonQuery();
        }
Beispiel #6
0
        public DataTable GetContatos()                                // SÓ QUERO TRAZER INFORMAÇÕES DO BANCO DE DADOS.
        {
            DbConnection conexao = DAOUtils.GetConexao();             // abri a conexao com o bando de dados
            DbCommand    comando = DAOUtils.GetComando(conexao);      // crie uma classe que vai executar comandos la na base de dados

            comando.CommandType = CommandType.Text;                   // tipo de comando que eu vou disparar para esta conexão, no caso tipo textp(ele é um ENUM)
            comando.CommandText = "SELECT * FROM CONTATOS";           // especifiquei qual comando SQL será executado
            DbDataReader reader    = DAOUtils.GetDataReader(comando); // e pedi para o método GetDataReader, gerar DataReader a partir de comando;
            DataTable    dataTable = new DataTable();

            dataTable.Load(reader);
            return(dataTable);    // teste para consulta usando o DataSet ao invés de serem jogados dentro de um DataReader através do DataTable.
        }
Beispiel #7
0
        //Implementação da leitura na forma de DataTable, permitindo apenas leitura do banco de dados
        public DataTable GetContatos()
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "SELECT * FROM CONTATOS";
            DbDataReader reader    = DAOUtils.GetDataReader(comando);
            DataTable    dataTable = new DataTable();

            dataTable.Load(reader);
            return(dataTable);
        }
        public void Atualizar(Contato contato)
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "UPDATE CONTATOS SET NOME = @nome, EMAIL = @email, TELEFONE = @telefone WHERE ID = @id";
            comando.Parameters.Add(new SqlParameter("@nome", contato.Nome));
            comando.Parameters.Add(new SqlParameter("@email", contato.Email));
            comando.Parameters.Add(new SqlParameter("@telefone", contato.Telefone));
            comando.Parameters.Add(new SqlParameter("@id", contato.Id));
            comando.ExecuteNonQuery();
        }
Beispiel #9
0
        public DataSet GetDataSetContatos()
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "SELECT * FROM CONTATOS";
            DbDataAdapter adapter = new SqlDataAdapter((SqlCommand)comando);
            DataSet       dataSet = new DataSet();

            adapter.Fill(dataSet, "CONTATOS");
            return(dataSet);
        }
Beispiel #10
0
        public void Excluir(int id)
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "DELETE FROM CONTATOS WHERE ID = @id";

            //Passa parametro para SQL Server e MySQl via metodo
            comando.Parameters.Add(DAOUtils.GetParametro("@id", id));

            //Executa comando SQL
            comando.ExecuteNonQuery();
        }
Beispiel #11
0
        public void Inserir(Contato contato)
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "INSERT INTO CONTATOS (NOME, EMAIL, TELEFONE) VALUES (@nome, @email, @telefone)";

            //Passa parametro para SQL Server e MySQl via metodo
            comando.Parameters.Add(DAOUtils.GetParametro("@nome", contato.Nome));
            comando.Parameters.Add(DAOUtils.GetParametro("@email", contato.Email));
            comando.Parameters.Add(DAOUtils.GetParametro("@telefone", contato.Telefone));

            //Executa comando SQL
            comando.ExecuteNonQuery();
        }
Beispiel #12
0
        public void Atualizar(Contato contato)
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "UPDATE CONTATOS SET NOME = @nome, EMAIL = @email, TELEFONE = @telefone WHERE ID = @id";

            //Passa parametro para SQL Server e MySQl via metodo
            comando.Parameters.Add(DAOUtils.GetParametro("@id", contato.Id));
            comando.Parameters.Add(DAOUtils.GetParametro("@nome", contato.Nome));
            comando.Parameters.Add(DAOUtils.GetParametro("@email", contato.Email));
            comando.Parameters.Add(DAOUtils.GetParametro("@telefone", contato.Telefone));

            //Executa comando SQL
            comando.ExecuteNonQuery();
        }
Beispiel #13
0
        //public DataTable GetContatos() --- Metodo DataTable e DataSet

        public DataSet GetContatos()
        {
            DbConnection conexao = DAOUtils.GetConexao();
            DbCommand    comando = DAOUtils.GetComando(conexao);

            comando.CommandType = CommandType.Text;
            comando.CommandText = "SELECT * FROM CONTATOS";
            DbDataAdapter adapter = new SqlDataAdapter((SqlCommand)comando);
            DataSet       ds      = new DataSet();

            adapter.Fill(ds, "CONTATOS");
            return(ds);

            /* DbDataReader reader = DAOUtils.GetDataReader(comando);
             * DataTable dataTable = new DataTable();
             * dataTable.Load(reader);
             * return dataTable;*/
        }
Beispiel #14
0
 public void Atualizar(Contato contato)
 {
     try
     {
         DbConnection conexao = DAOUtils.GetConexao();
         DbCommand    comando = DAOUtils.GetComando(conexao);
         comando.CommandType = CommandType.Text;
         comando.CommandText = "UPDATE CONTATOS SET NOME = @nome, EMAIL = @email, TELEFONE = @telefone WHERE ID = @id";
         comando.Parameters.Add(DAOUtils.GetParameter("@nome", contato.Nome));
         comando.Parameters.Add(DAOUtils.GetParameter("@email", contato.Email));
         comando.Parameters.Add(DAOUtils.GetParameter("@telefone", contato.Telefone));
         comando.Parameters.Add(DAOUtils.GetParameter("@id", contato.Id));
         comando.ExecuteNonQuery(); // QUANDO A QUERY NAO RETORNA NADA
     }
     catch (Exception e)
     {
         MessageBox.Show("Falha ao salvar dados" + e.Message);
     }
 }