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.Parameters.Add(DAOUtils.GetParameter("@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)"; // 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(); }
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.Parameters.Add(new MySqlParameter("@nome", contato.Nome)); //comando.Parameters.Add(new MySqlParameter("@email", contato.Email)); //comando.Parameters.Add(new MySqlParameter("@telefone", contato.Telefone)); 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(); }
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); } }
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.Parameters.Add(new MySqlParameter("@nome", contato.Nome)); //comando.Parameters.Add(new MySqlParameter("@email", contato.Email)); //comando.Parameters.Add(new MySqlParameter("@telefone", contato.Telefone)); //comando.Parameters.Add(new MySqlParameter("@id", contato.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(); }