Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

InitConAdapter : パート 1

InitConAdapter メソッドは、conAdapter という名前で CacheDataAdapter インスタンスを作成します。このアダプタは、データ・セットを Caché の Provider.Contact テーブルに接続します。以下に示すこのメソッドの最初の部分は、次のように動作します。

  1. conAdapter によってサポートされる SQL コマンドを定義する SQL 文字列を作成します。ただし、挿入は、Provider.Contact で定義されているストアド・プロシージャによって処理されます。storedproc 変数には、そのストアド・プロシージャへの呼び出しを定義する文字列を指定します。

  2. CacheDataAdapter インスタンスを作成します。これは、SQL の SELECTCacheConnection インスタンスが含まれた文字列で初期化されます。

  3. アダプタの Insert コマンドを作成します。

  4. AddInputParams ヘルパー・メソッドを使用して、入力パラメータをアダプタの Insert コマンドに追加します。

  5. Output パラメータを作成し、それを Insert コマンドに追加します。このパラメータは、Provider.ContactID 列を表します。ストアド・プロシージャでは、列の値は出力パラメータとして処理されます。

このメソッドの本文を、PhoneForm.csInitConAdapter スタブに追加します。


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

FeedbackOpens in a new tab