Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRISOpens in a new window, see the InterSystems IRIS Migration Guide and Migrating to InterSystems IRIS, both available on the WRC Distributions pageOpens in a new window (login required).

A Simple Query

To execute an SQL command that does not involve any parameters you need only use CacheCommand. CacheDataReader provides very efficient forward and read only access to a stream of data returned by a query. The following method uses CacheCommand and CacheDataReader to retrieve and display all of the “Business” contacts in the database.


public void DisplayBusinessContacts()
{
try{
    string sql = 
      "Select %ID, Name, ContactType From Provider.Contact Where +
                             "ContactType %startswith 'Business' Order By Name";

    CacheCommand command = new CacheCommand(sql, cnCache);
    CacheDataReader reader = command.ExecuteReader();
    while (reader.Read())
    {
       Console.WriteLine("ID: {0} Name: {1}", reader[reader.GetOrdinal("ID")], 
                                            reader[reader.GetOrdinal("Name")]);
    }  
  }
catch (CacheException e){}
}
Copy code to clipboard

Note that cnCache represents an open CacheConnection instance.

FeedbackOpens in a new window