Skip to main content


The AddContact method creates a new contact. It creates a new row in the data set containing the information displayed in the Edit Contact Information GUI panel. It then propagates the data set changes to Caché. The event handler for the Create button clicks invokes AddContact. The event handler is already coded for you. Here are some more details about the AddContact functionality:

  1. It creates a new row for the Contacts table in the data set.

  2. It assigns the values from the GUI elements to the new row's fields.

  3. It adds the new row to the data set.

  4. It invokes Update on conAdapter. This is the CacheDataAdapter object that connnects the data set to the Provider.Contact table. Update propagates the changes to the data set data to Caché. It also reloads the Caché data into the data set.

  5. It retrieves the value of the ID field from the new row and displays it on the GUI. After Update is invoked, this value is available in the new row.

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

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

private void AddContact()
   DataRow newRow = ds.Tables["Contacts"].NewRow();
   newRow["Name"] = txtConName.Text;
   newRow["ContactType"] = comboBox1.SelectedItem.ToString();
   conAdapter.Update(ds, "Contacts");
   txtConId.Text = newRow["ID"].ToString();
FeedbackOpens in a new tab