private void Actualizar() { int CustId = Convert.ToInt32(txtCustomerId.Text); using (AdbEntities context = new AdbEntities()) { Customer oCliente = context.Customer.SingleOrDefault(p => p.CustomerID == CustId); //MessageBox.Show(oCliente.LastName); oCliente.NameStyle = chkNameStyle.Checked; oCliente.Title = txtTitle.Text; oCliente.FirstName = txtFirstName.Text; oCliente.MiddleName = txtMiddleName.Text; oCliente.LastName = txtLastName.Text; oCliente.Suffix = txtSuffiix.Text; oCliente.CompanyName = txtCompanyName.Text; oCliente.SalesPerson = txtSalesPerson.Text; oCliente.EmailAddress = txtEmailAddress.Text; oCliente.Phone = txtPhone.Text; oCliente.PasswordHash = txtPasswordHash.Text; oCliente.PasswordSalt = txtPasswordSalt.Text; context.SaveChanges(); } }
private void Insertar() { try { using(AdbEntities context = new AdbEntities()) { Customer oCliente = new Customer { NameStyle = chkNameStyle.Checked, Title = txtTitle.Text, FirstName = txtFirstName.Text, MiddleName = txtMiddleName.Text, LastName = txtLastName.Text, Suffix = txtSuffiix.Text, CompanyName = txtCompanyName.Text, SalesPerson = txtSalesPerson.Text, EmailAddress = txtEmailAddress.Text, Phone = txtPhone.Text, PasswordHash = txtPasswordHash.Text, PasswordSalt = txtPasswordSalt.Text, ModifiedDate = DateTime.Now }; MessageBox.Show(string.Format("Id = {0} - LastName = {1}", oCliente.CustomerID, oCliente.LastName)); context.Customer.Add(oCliente); context.SaveChanges(); } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { MessageBox.Show(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationErrors.ValidationErrors)); } } } finally { CargarGrid(); } }
private void button4_Click(object sender, EventArgs e) { int CustId = Convert.ToInt32(txtCustomerId.Text); using (AdbEntities context = new AdbEntities()) { //Customer oCliente = context.Customer.SingleOrDefault(p => p.CustomerID == CustId); Customer oCliente = (from q in context.Customer where q.CustomerID == CustId select q).First(); try { context.Customer.Remove(oCliente); context.SaveChanges(); CargarGrid(); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } } }