Skip to main content

InitContactList

The following method initializes the ContactList property by filling it with the object IDs for all of the Contact instances in the database. The method uses the Provider.Contact ByName query to do this. The method does the following:

  1. Retrieves the CacheCommand returned by ByName. Note that an open CacheConnection instance must be passed to ByName.

  2. Creates a new CacheParameter object to represent the query's input parameter. The method assigns null as the value of the parameter. Passing null as the input value of the parameter causes all of the Contact instances to be matches.

  3. Adds the parameter to the CacheCommand object.

  4. Invokes the CacheCommand object's ExecuteReader method to execute ByName.

  5. Iterates through the results in the CacheReader object returned by ExecuteReader and places the data in ContactList.

Here is the method. Add the body of the method to the InitContactList stub in PhoneFormObj.cs.


private void InitContactList()
{
  CacheCommand command = Contact.ByName(cnCache);
  CacheParameter name_param = new CacheParameter("Name", CacheDbType.NVarChar);
  name_param.Value = null;
  command.Parameters.Add(name_param);
  CacheDataReader reader = command.ExecuteReader();
  while (reader.Read())
  {
    string id = reader[reader.GetOrdinal("ID")].ToString();
    ContactList.Add(id); 
   }
  reader.Close(); 
 }
Note:

Part III: Caché Managed Provider: Relational Interface provides more information on using CacheCommand and CacheDataReader.

FeedbackOpens in a new tab