private void Submit(object sender, EventArgs e) { using (UniversityDataContext context = new UniversityDataContext(App.UniversityconnectionString)) { Student st = new Student() { ID = Int32.Parse(ID_text.Text), Name = Name_text.Text, LastName = LastName_text.Text }; context.Students.InsertOnSubmit(st); context.SubmitChanges(); MessageBox.Show("Student Added Successfully"); } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { using (UniversityDataContext context = new UniversityDataContext(App.UniversityconnectionString)) { var StudentLoaded = (from Stud in context.Students where Stud.ID == Int32.Parse(ID_txt.Text) select Stud).FirstOrDefault(); if (StudentLoaded != null) { StudentLoaded.Name = Name_txt.Text; StudentLoaded.LastName = LastName_txt.Text; context.SubmitChanges(); } } }
private void DeleteRegister(object sender, EventArgs e) { if (StudentListBox.SelectedIndex!=-1) { Student st = (Student)StudentListBox.SelectedItem; using (UniversityDataContext context = new UniversityDataContext(App.UniversityconnectionString)) { context.Students.Attach(st); context.Students.DeleteOnSubmit(st); context.SubmitChanges(); MessageBox.Show("Student Deleted Successfully"); StudentListBox.ItemsSource = null; LoadStudents(); } } else { MessageBox.Show("A Student must be selected in order to delete it!"); } }
private void DeleteRegister(object sender, EventArgs e) { if (StudentListBox.SelectedIndex != -1) { Student st = (Student)StudentListBox.SelectedItem; using (UniversityDataContext context = new UniversityDataContext(App.UniversityconnectionString)) { context.Students.Attach(st); context.Students.DeleteOnSubmit(st); context.SubmitChanges(); MessageBox.Show("Student Deleted Successfully"); StudentListBox.ItemsSource = null; LoadStudents(); } } else { MessageBox.Show("A Student must be selected in order to delete it!"); } }