CacheDataReader: Update
The following code executes an SQL UPDATE on a row of 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 the UPDATE using the CMP CacheCommand and CacheDataReader classes.
-
Displays the number of affected rows.
-
Closes the 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 update String sql = "UPDATE MVFILE.PERSON (AGE,PHONE) VALUES" + " ('41','111-111-1111,222-222-2222') WHERE NAME='IDLE,JIM'"; CacheCommand command = new CacheCommand(sql, cnCache); int rows = command.ExecuteNonQuery(); //Display the number of affected rows Console.WriteLine("rows {0}", rows); //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.