public void Excluir(BLL.NoticiasBLL n) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"DELETE FROM TBNoticia WHERE ID =@id"; cmd.Parameters.AddWithValue("@id", n.Id); cmd.ExecuteNonQuery(); con.Desconectar(); }
protected void btnCadastrar_Click(object sender, EventArgs e) { BLL.NoticiasBLL n = new BLL.NoticiasBLL(); DAL.NoticiasDAL nDAL = new DAL.NoticiasDAL(); n.Titulo = txtTitulo.Text; n.Conteudo = txtConteudo.Text; n.Imagem = txtImagem.Text; n.IdCategoria = Convert.ToInt32(ddlCategoria.SelectedValue); nDAL.Cadastrar(n); Response.Write("<script>alert('Noticia Cadastrada')</script>"); txtTitulo.Text = ""; txtConteudo.Text = ""; txtImagem.Text = ""; ddlCategoria.SelectedIndex = 0; txtDescricao.Focus(); }
public void Cadastrar(BLL.NoticiasBLL n) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"INSERT INTO TBNoticia( TITULO, CONTEUDO, IMAGEM, ID_CATEGORIA) VALUES( @titulo, @conteudo, @imagem, @id_categoria)"; cmd.Parameters.AddWithValue("@titulo", n.Titulo); cmd.Parameters.AddWithValue("@conteudo", n.Conteudo); cmd.Parameters.AddWithValue("@imagem", n.Imagem); cmd.Parameters.AddWithValue("@id_categoria", n.IdCategoria); cmd.ExecuteNonQuery(); con.Desconectar(); }