Exemple #1
0
 private void buttonDisplayAll_Click(object sender, EventArgs e)
 {
     using (WindowsFormsDatabaseEntities myEntities = new WindowsFormsDatabaseEntities())
     {
         var customers = from customer in myEntities.CustomerDatas
                         select customer;
         listCustomers = customers.ToList();
     }
     DisplayCustomer(customerListIndex);
 }
Exemple #2
0
 private void buttonAddRecord_Click(object sender, EventArgs e)
 {
     using (var myEntities = new WindowsFormsDatabaseEntities())
     {
         CustomerData addedCustomer = new CustomerData();
         addedCustomer.Name     = textBoxName.Text;
         addedCustomer.Address  = textBoxAddress.Text;
         addedCustomer.City     = textBoxCity.Text;
         addedCustomer.Postcode = textBoxPostcode.Text;
         addedCustomer.Phone    = textBoxPhoneNumber.Text;
         //var lastRecord = (from myRecord in myEntities.Customers
         //                  orderby myRecord.Id descending
         //                  select myRecord).First();
         //addedCustomer.Id = (int)lastRecord.Id + 1;
         //myEntities.Configuration.AutoDetectChangesEnabled = true;
         myEntities.CustomerDatas.Add(addedCustomer);
         myEntities.SaveChanges();
     }
 }