private void btnAgregar_Click(object sender, EventArgs e) { using (SupermercadoEntity db = new SupermercadoEntity()) { if (id == null) { productos = new Productos(); } productos.nombre = tfNombre.Text; productos.precio = int.Parse(tfPrecio.Text); if (id == null) { db.Productos.Add(productos); } else { db.Entry(productos).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); this.Close(); } }
private void Actualizar() { using (SupermercadoEntity db = new SupermercadoEntity()) { var lista = from d in db.Productos select d; dataGridView1.DataSource = lista.ToList(); } }
private void CargarCampos() { using (SupermercadoEntity db = new SupermercadoEntity()) { productos = db.Productos.Find(id); tfNombre.Text = productos.nombre; tfPrecio.Text = productos.precio.ToString(); } }
private void button3_Click(object sender, EventArgs e) { int?id = GetID(); if (id != null) { using (SupermercadoEntity db = new SupermercadoEntity()) { Productos producto = db.Productos.Find(id); db.Productos.Remove(producto); db.SaveChanges(); } Actualizar(); } }