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?

パラメータを使用したクエリ

入力パラメータを使用した複雑なクエリを実行するには、CacheParameter を使用して、パラメータを定義する必要があります。以下のメソッドでは、特定のタイプの連絡先をすべて表示します。このタイプは、実行時にメソッドに渡されます。


public void DisplayContacts(string type)
{
 try{
   string sql = "Select %ID, Name, ContactType From Provider.Contact "+
                                "Where ContactType %startswith ? Order By Name";
   
   CacheParameter type_param = new CacheParameter();
   type_param.CacheDbType = CacheDbType.NVarChar;
   type_param.Direction = ParameterDirection.Input;
   type_param.Size = 50;
   type_param.ParameterName="ContactType";
   type_param.Value = type;
   
   CacheCommand command = new CacheCommand(sql, cnCache);
   command.Parameters.Add(type_param);
   CacheDataReader reader = command.ExecuteReader();
   while (reader.Read())
   {
     Console.WriteLine("ID: {0} Name: {1}", reader[reader.GetOrdinal("ID")], 
                                             reader[reader.GetOrdinal("Name")]);
   }
 }
 catch (CacheException e){}
}
 

cnCache は、開いている CacheConnection インスタンスを表します。

FeedbackOpens in a new tab