private void btExcluirAluno_Click(object sender, RoutedEventArgs e) { using (var bd = new EscolaDataContext()) { if (MessageBox.Show("Confirma exclusão?", "Remover", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { Aluno aluno = (Aluno)((Button)sender).DataContext; bd.Alunos.Attach(aluno); bd.Alunos.DeleteOnSubmit(aluno); bd.SubmitChanges(); CarregarAlunos(); } } }
private void btAdicionar_Click(object sender, RoutedEventArgs e) { Aluno novoAluno = new Aluno { Nome = txtNome.Text, Cidade = txtCidade.Text }; using (var bd = new EscolaDataContext()) { bd.Alunos.InsertOnSubmit(novoAluno); bd.SubmitChanges(); CarregarAlunos(); MessageBox.Show("Aluno adicionado!"); } }