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).

InitConAdapter: Part 1

The InitConAdapter method creates a CacheDataAdapter instance named conAdapter. This adapter connects the data set to the Provider.Contact table in Caché. The first part of this method, displayed below, does the following:

  1. Creates the SQL strings defining the SQL commands supported by conAdapter. Note that inserts are handled by a stored procedure defined in Provider.Contact. The storedproc variable contains the string defining the call to the stored procedure.

  2. Creates the CacheDataAdapter instance. It is initialized with the string containing the SQL SELECT and the CacheConnection instance.

  3. Creates the Insert command for the adapter.

  4. Adds the input parameters to the adapter's Insert command using the AddInputParams helper method.

  5. Creates an Output parameter and adds it to the Insert command. The parameter represents the Provider.Contact ID column. The stored procedure treats the column's values as output parameters.

Add the body of the method to the InitConAdapter stub in PhoneForm.cs.


private void InitConAdapter()
{
  string selectSQL = "Select %ID, Name, ContactType from Provider.Contact " +
                      "Order By Name";
  string updateSQL = "Update Provider.Contact Set Name = ?, ContactType = ? " +
                     "where ID = ?";
  string deleteSQL = "Delete from Provider.Contact where ID = ?";
  string storedproc = "{call Provider.Contact_InsertData(?,?,?)}";
  
  conAdapter = new CacheDataAdapter(selectSQL,cnCache); 
     
  //Create InsertCommand using stored procedure
   conAdapter.InsertCommand = cnCache.CreateCommand();
   conAdapter.InsertCommand.CommandText = storedproc;

  //Add input parameters for InsertCommand
   AddInputParams(conAdapter.InsertCommand, "Name", "ContactType");

  //Add output parameter - the new row id - for InsertCommand
   CacheParameter Id = new CacheParameter();
   Id.ParameterName = "ID";
   Id.CacheDbType = CacheDbType.Int;
   Id.Direction = ParameterDirection.Output;
   Id.SourceColumn = "ID";
   
  conAdapter.InsertCommand.Parameters.Add(Id);
  ...
Copy code to clipboard
FeedbackOpens in a new window