Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        public void Insere(ExercicioModelo m)
        {
            SqlConnection conexao = new SqlConnection(Conexao.getConexao());
            try
            {
                //Comando de inserir:
                SqlCommand cmd = new SqlCommand("INSERT INTO Exercicio (Musculo_idMusculo, Nivel_idNivel, nome, descricao) VALUES (@idMusculo, @idNivel, @nome, @descricao)", conexao);

                cmd.CommandType = CommandType.Text;

                cmd.Parameters.Add("@idMusculo", m.getIdMusculo());
                cmd.Parameters.Add("@idNivel", m.getIdNivel());
                cmd.Parameters.Add("@nome", m.getNome());
                cmd.Parameters.Add("@descricao", m.getDescricao());

                //Abre conexao
                conexao.Open();

                //Executa
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw new Exception("Erro ao inserir no Banco de Dados: " + ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro: " + ex.Message);
            }
            finally
            {
                conexao.Close();
            }
        }