Skip to main content

CacheDataReader: Query

The following .NET code executes an SQL SELECT * on the MVFILE.PERSON table. In more detail, the code does the following:

  1. Creates a connection to Caché using the CMP CacheConnection class.

  2. Opens the database connection.

  3. Creates and executes a query using the CMP CacheCommand and CacheDataReader classes.

  4. Iterates through the query results and displays the data.

  5. Closes the database connection.


 //Create the connection
 string cacheString =
 "Server=localhost;Port=1972; Log File=c:\\MVTutorial.log;Namespace=MYACCOUNT;" 
 + "Password=SYS;User ID=_system;";
 cnCache = new CacheConnection(cacheString);

 //Open the connection
 cnCache.Open();

 //Create and execute the query
 string sql = "SELECT * FROM MVFILE.PERSON"; 
 CacheCommand command = new CacheCommand(sql, cnCache);
 CacheDataReader reader = command.ExecuteReader();

 //Display the results
 while (reader.Read())
 {
   for (int i = 0; i < reader.FieldCount; i++)
   {
     Console.Write(reader[i] + " " );
   }
  Console.WriteLine();
  }
  
 //Close the connection
 cnCache.Close();
 
Note:

The above code is contained in RelationalAccess.cs. The file is in <cachesys>\Dev\tutorials\mv. Executing the .NET Examples contains step-by-step instructions for executing this code.

FeedbackOpens in a new tab