Ejemplo n.º 1
0
        public void delete(MusculoModelo m)
        {
            
            SqlConnection conexao = new SqlConnection(Conexao.getConexao());
            try
            {
                //Comando de deletar:
                SqlCommand cmd = new SqlCommand("DELETE Musculo where idMusculo = @idMusculo", conexao);

                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@idMusculo", m.getIdMusculo());

                //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();
            }
        }
Ejemplo n.º 2
0
        public void Insere(MusculoModelo m)
        {
            SqlConnection conexao = new SqlConnection(Conexao.getConexao());
            try
            {
                //Comando de inserir:
                SqlCommand cmd = new SqlCommand("INSERT INTO MUSCULO (descricao) VALUES (@descricao)", conexao);

                cmd.CommandType = CommandType.Text;
                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();
            }
        }