Skip to main content

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){}
}

Note that cnCache represents an open CacheConnection instance.

FeedbackOpens in a new tab