public void DeleteMethodOK() { //create an instance of the class we want to create clsTrainerCollection AllTrainers = new clsTrainerCollection(); //create an item of test data clsTrainer TestItem = new clsTrainer(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.TrainerID = 44; TestItem.FullName = "Ross O'Donegan"; TestItem.EmailAddress = "*****@*****.**"; TestItem.Gender = "Male"; TestItem.Retrained = true; TestItem.DateOfBirth = DateTime.Parse("17/05/2000"); //set ThisTrainer to the test data AllTrainers.ThisTrainer = TestItem; //add the record PrimaryKey = AllTrainers.Add(); //set the primary key of the test data TestItem.TrainerID = PrimaryKey; //find the record AllTrainers.ThisTrainer.Find(PrimaryKey); //delete the record AllTrainers.Delete(); //now find the record Boolean Found = AllTrainers.ThisTrainer.Find(PrimaryKey); //test to see that the record was not found Assert.IsFalse(Found); }
protected void btnYes_Click(object sender, EventArgs e) { //create a new instance of the Trainer collection clsTrainerCollection AllTrainers = new clsTrainerCollection(); //find the record to delete AllTrainers.ThisTrainer.Find(TrainerID); //delete the record AllTrainers.Delete(); //redirect back to the main page Response.Redirect("DefaultTrainer.aspx"); }