Esempio n. 1
0
        //提交
        private void button1_Click(object sender, EventArgs e)
        {
            const string ConnectionString = @"Data Source=(localdb)\mssqllocaldb;Initial Catalog=contacts_data;Integrated Security=true;";
            Contacts     aNewContact      = new Contacts {
                name = name1, telephone = telephone1, organization = organization1, email = email1, remarks = remarks1
            };

            using (contact_dataDataContext aDataContext = new contact_dataDataContext(ConnectionString))
            {
                aDataContext.Contacts.InsertOnSubmit(aNewContact);
                aDataContext.SubmitChanges();
                this.Close();
            }
        }
Esempio n. 2
0
 private void Ondelete(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         const string ConnectionString = @"Data Source=(localdb)\mssqllocaldb;Initial Catalog=contacts_data;Integrated Security=true;";
         string       id = Interaction.InputBox("请输入要删除的联系人id", "删除", "例如,输入:3");
         using (contact_dataDataContext aDataContext = new contact_dataDataContext(ConnectionString))
         {
             Contacts aExistContact = (from r in aDataContext.Contacts where r.id == int.Parse(id) select r).FirstOrDefault();
             if (aExistContact != null)
             {
                 aDataContext.Contacts.DeleteOnSubmit(aExistContact);
                 aDataContext.SubmitChanges();
             }
         }
         _Model           = new MainModel();
         this.DataContext = _Model;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 3
0
 public MainModel()
 {
     DataContext = new contact_dataDataContext(ConnectionString);
 }