示例#1
0
        public List <MODEL.Autor> Select()
        {
            List <MODEL.Autor> lstAutor = new List <MODEL.Autor>();
            SqlConnection      conexao  = new SqlConnection(strCon);
            string             sql      = "Select * from Autor";
            SqlCommand         cmd      = new SqlCommand(sql, conexao);

            conexao.Open();

            try
            {
                SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    MODEL.Autor aut = new MODEL.Autor();
                    aut.Id   = Convert.ToInt32(reader[0].ToString());
                    aut.Nome = reader["Nome"].ToString();
                    lstAutor.Add(aut);
                }
            }
            catch
            {
                Console.WriteLine("Erro na seleção de autores!");
            }
            finally
            {
                conexao.Close();
            }
            return(lstAutor);
        }
示例#2
0
        public void Delete(MODEL.Autor aut)
        {
            SqlConnection conexao = new SqlConnection(strCon);
            string        sql     = "Delete from Autor where id=@id;";
            SqlCommand    cmd     = new SqlCommand(sql, conexao);

            cmd.Parameters.AddWithValue("@id", aut.Id);
            conexao.Open();
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch
            {
                Console.WriteLine("Erro na Remoção de Autores!");
            }
            finally
            {
                conexao.Close();
            }
        }
示例#3
0
        public void Insert(MODEL.Autor aut)
        {
            SqlConnection conexao = new SqlConnection(strCon);
            string        sql     = "Insert into Autor values (@nome)";
            SqlCommand    cmd     = new SqlCommand(sql, conexao);

            cmd.Parameters.AddWithValue("@nome", aut.Nome);
            conexao.Open();

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch
            {
                Console.WriteLine("Erro ao inserir autor!");
            }
            finally
            {
                conexao.Close();
            }
        }
示例#4
0
        public void Update(MODEL.Autor aut)
        {
            SqlConnection conexao = new SqlConnection(strCon);
            string        sql     = "Update Autor set nome=@nome, ";

            SqlCommand cmd = new SqlCommand(sql, conexao);

            cmd.Parameters.AddWithValue("@nome", aut.Nome);
            conexao.Open();

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch
            {
                Console.WriteLine("Erro ao atualizar o autor!");
            }
            finally
            {
                conexao.Close();
            }
        }
示例#5
0
 public void Delete(MODEL.Autor aut)
 {
     DAL.Autor dalAut = new DAL.Autor();
     dalAut.Delete(aut);
 }
示例#6
0
 public void Update(MODEL.Autor aut)
 {
     DAL.Autor dalAut = new DAL.Autor();
     dalAut.Update(aut);
 }
示例#7
0
 public void Insert(MODEL.Autor aut)
 {
     DAL.Autor dalAut = new DAL.Autor();
     dalAut.Insert(aut);
 }