Skip to main content

Creating a New Object

Here is a sample of .NET code that does the following:

  1. Creates a new instance of Provider.Contact.

  2. Assigns values to the new Contact instance's Name and ContactType properties.

  3. Saves the new Contact instance.

  4. Uses the CacheStatus instance returned from Save to determine whether the object was successfully saved.

  5. If the Contact instance is saved, it writes the new object's ID value to the console. Note that a Caché object only acquires an object ID the first time it is saved.

  6. If the Contact instance is not saved, it writes an error message to the console.


try
{
    Provider.Contact contact = new Provider.Contact(cnCache);
    contact.Name = "Smith,John";
    contact.ContactType = "Business";
    CacheStatus status = contact.Save();
    if (status.IsOK)
    {
      Console.WriteLine("Id is: {0}" , contact.Id());
    }
    else
    {
      Console.WriteLine("Error creating object");
    }
}
catch (Exception e) { }     
  

Note that cnCache represents an open CacheConnection instance.

FeedbackOpens in a new tab