Skip to main content


The DeleteContact method removes a contact, and its phone numbers, from the data base. It first removes the rows from the data set and then propagates these changes to Caché. The event handler for the Delete button invokes DeleteContact. Here are some more details about what DeleteContact does:

  1. It reads the Contact ID from the text box on the GUI panel.

  2. It uses the Find method of the ADO.NET DataRowCollection class to locate the row in the Contacts data table with the correct ID value.

  3. It uses the Delete method of the DataRow class to mark the targeted row for deletion. Note that due to the parent-child relationship between Contacts and PhoneNumbers, this also marks the child rows in PhoneNumbers for deletion.

  4. It invokes Update on phoneAdapter. This is the CacheDataAdapter object that connects the data set to the Provider.PhoneNumber table. Update removes the rows marked for delete in PhoneNumbers from the Provider.PhoneNumbers table in Caché.

  5. It invokes Update on conAdapter. This is the CacheDataAdapter object that connnects the data set to the Provider.Contact table. Update removes the rows marked for delete in Contacts from the Provider.Contact table in Caché.

  6. It invokes ClearPhone form, a method already coded in PhoneForm.cs, to clear the contact's information from the Edit Contact Information GUI panel.

  7. It invokes DisplayTreeView to redisplay the data in the GUI's tree.

Add the method body to the DeleteContact stub in PhoneForm.cs.

private void DeleteContact()
   DataRow targetRow = ds.Tables["Contacts"].Rows.Find(txtConId.Text);
   conAdapter.Update(ds, "Contacts");


When updating a data source from a data set, it is important to update the affected rows in the correct order. For the case of deletes, the child rows must be updated before the parent rows. This is why the above code updates Provider.PhoneNumber before Provider.Contact.

FeedbackOpens in a new tab