private void EditButton_Click(object sender, RoutedEventArgs e) { try { CustomersDataContext dataContext = new CustomersDataContext(); Customer customerRow = MyDataGrid.SelectedItem as Customer; string m = customerRow.CustomerID; Customer customer = (from p in dataContext.Customers where p.CustomerID == customerRow.CustomerID select p).Single(); customer.CompanyName = customerRow.CompanyName; customer.ContactName = customerRow.ContactName; customer.Country = customerRow.Country; customer.City = customerRow.City; customer.Phone = customerRow.Phone; dataContext.SubmitChanges(); MessageBox.Show("Row Updated Successfully."); LoadCustomers(); } catch (Exception Ex) { MessageBox.Show(Ex.Message); return; } }
private void LoadCustomers() { CustomersDataContext cd = new CustomersDataContext(); var customers = (from p in cd.Customers select p).Take(10); MyDataGrid.ItemsSource = customers; LoadButton.Content = "Customers Loaded"; }
private void DeleteButton_Click(object sender, RoutedEventArgs e) { CustomersDataContext cd = new CustomersDataContext(); Customer customerRow = MyDataGrid.SelectedItem as Customer; var customer = (from p in cd.Customers where p.CustomerID == customerRow.CustomerID select p).Single(); cd.Customers.DeleteOnSubmit(customer); cd.SubmitChanges(); MessageBox.Show("Row Deleted Successfully."); LoadCustomers(); }