public void update(ExercicioModelo m) { SqlConnection conexao = new SqlConnection(Conexao.getConexao()); try { //Comando de update: SqlCommand cmd = new SqlCommand("UPDATE Exercicio set Musculo_idMusculo = @idMusculo, Nivel_idNivel = @idNivel, nome = @nome, @descricao = descricao WHERE idExercicio = @idExercicio", conexao); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@idExercicio", m.getIdExercicio()); cmd.Parameters.AddWithValue("@idMusculo", m.getIdMusculo()); cmd.Parameters.AddWithValue("@idNivel", m.getIdNivel()); cmd.Parameters.AddWithValue("@nome", m.getNome()); cmd.Parameters.AddWithValue("@descricao", m.getDescricao()); //Abre conexao conexao.Open(); //Executa cmd.ExecuteNonQuery(); } catch (SqlException ex) { throw new Exception("Erro ao deletar no Banco de Dados: " + ex.Message); } catch (Exception ex) { throw new Exception("Erro: " + ex.Message); } finally { conexao.Close(); } }
public void delete(ExercicioModelo m) { SqlConnection conexao = new SqlConnection(Conexao.getConexao()); try { //Comando de deletar: SqlCommand cmd = new SqlCommand("DELETE Exercicio where idExercicio = @idExercicio", conexao); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@idExercicio", m.getIdExercicio()); //Abre conexao conexao.Open(); //Executa cmd.ExecuteNonQuery(); } catch (SqlException ex) { throw new Exception("Erro ao deletar no Banco de Dados: " + ex.Message); } catch (Exception ex) { throw new Exception("Erro: " + ex.Message); } finally { conexao.Close(); } }