CacheDataReader: Query
The following .NET code executes an SQL SELECT * on the MVFILE.PERSON table. In more detail, the code does the following:
-
Creates a connection to Caché using the CMP CacheConnection class.
-
Opens the database connection.
-
Creates and executes a query using the CMP CacheCommand and CacheDataReader classes.
-
Iterates through the query results and displays the data.
-
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();
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.