Пример #1
0
 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;
     }
 }
Пример #2
0
        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";
        }
Пример #3
0
        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();
        }