SHARE
TWEET

Delete izbranog studenta

binarche Apr 19th, 2019 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  // Delete
  2.         // izbrisati izabranog studenta
  3.         private void btnBrisi_Click(object sender, RoutedEventArgs e)
  4.         {
  5.             string txtBrisi = lstBoxTrazi.SelectedItem.ToString();
  6.  
  7.             Student brisi = (from s in DC.Students
  8.                              where s.Ime == lstBoxTrazi.SelectedItem.ToString()
  9.                              select s).Single();
  10.  
  11.             //  Student brisi = DC.Students.Single(s=>s.Ime == lstBoxTrazi.SelectedItem.ToString()); // preko lambda izraza
  12.  
  13.             MessageBoxResult rez = MessageBox.Show("Da li si siguran da zelis da izbrises podatke o " + txtBrisi + "?", "Brisanje", MessageBoxButton.YesNo);
  14.  
  15.             if (rez == MessageBoxResult.Yes)
  16.             {
  17.                 // ubacuje se u red za brisanje
  18.                 DC.Students.DeleteOnSubmit(brisi);
  19.  
  20.                 try
  21.                 {
  22.                     // izrsavaju se promene
  23.                     DC.SubmitChanges();
  24.                     MessageBox.Show("Podaci o " + txtBrisi + " su uspesno izbrisani iz baze", "Obavestenje", MessageBoxButton.OK, MessageBoxImage.Information);
  25.                     lstViewNadjen.ItemsSource = null;
  26.                     lstBoxTrazi.ItemsSource = null;
  27.                     lstViewNadjen.Visibility = System.Windows.Visibility.Collapsed;
  28.                     lstBoxTrazi.Visibility = System.Windows.Visibility.Collapsed;
  29.                     txtTrazi.Text = "";
  30.                 }
  31.  
  32.                 catch (Exception ex)
  33.                 {
  34.                     MessageBox.Show("Ne moze da se izbrise iz baze" + ex);
  35.                 }
  36.             }
  37.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top