Exemple #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var result = MessageBox.Show("Are you sure to delete this item", "Delete Selected", MessageBoxButton.YesNoCancel);

            if (result.ToString() == "Yes")
            {
                if (selectedItem != -1)
                {
                    try
                    {
                        con             = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DotNetFinalProject.Properties.Settings.MapuaUniversity"].ConnectionString);
                        cmd             = new SqlCommand("dbo.DeleteStudent", con);
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@id", selectedItem);
                        con.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        student.RefreshList();
                        student.FillList();
                        con.Close();
                    }
                }
            }
        }