private void createDataContext() { CustomerdataContext cdc = new CustomerdataContext(); GridView.DataSource = cdc.Customers.Join(cdc.Addresses, z => z.CustomerId, y => y.Customer.CustomerId, (y, z) => new { y.CustomerId, y.Firstname, y.Lastname, z.Street, z.City, z.State, z.Zip }).ToList().AsReadOnly(); GridView.Columns[0].Visible = false; }
private void UpdBtn_Click(object sender, System.EventArgs e) { CustomerdataContext cdc = new CustomerdataContext(); if (string.IsNullOrEmpty(FNtxtBx.Text)) { MessageBox.Show("First Name cannot be empty"); } else { var customerID = new SqlParameter("@id", DisplayForm.currentID); var customerFirstName = new SqlParameter("@firstName", FNtxtBx.Text); cdc.Database.ExecuteSqlRaw("EXECUTE updateCustomer @firstName, @id", customerFirstName, customerID); this.Close(); } }
private void UpdateAddressButton_Click(object sender, EventArgs e) { CustomerdataContext cdc = new CustomerdataContext(); if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text) || string.IsNullOrEmpty(textBox3.Text) || string.IsNullOrEmpty(textBox4.Text)) { MessageBox.Show("No fields may be empty!"); } else if (textBox3.Text.Length > 2) { MessageBox.Show("Use state abbreviations please"); } else { Address newAddy = cdc.Addresses.Single(upd => upd.CustomerId == DisplayForm.currentID); newAddy.Street = textBox1.Text; newAddy.City = textBox2.Text; newAddy.State = textBox3.Text; newAddy.Zip = textBox4.Text; cdc.SaveChanges(); this.Close(); } }