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?

挿入

以下のメソッドは、Contact テーブルに行を挿入します。ここでは、CacheCommand と 2 つの CacheParameter インスタンスを使用しています。1 つのインスタンスは Name を表し、もう 1 つは ContactType を表しています。


 public void InsertContact(string name, string type)
 {
    try{
     string sql = "Insert into Provider.Contact(Name,ContactType) Values(?,?)";
     CacheCommand command= new CacheCommand(sql, cnCache);

     CacheParameter name_param = new CacheParameter();
     name_param.CacheDbType = CacheDbType.NVarChar;
     name_param.ParameterName = "Name";
     name_param.Direction = ParameterDirection.Input;
     name_param.Value = name;

     CacheParameter type_param = new CacheParameter();
     type_param.CacheDbType = CacheDbType.NVarChar;
     type_param.ParameterName = "ContactType";
     type_param.Direction = ParameterDirection.Input;
     type_param.Value = type;
     
     command.Parameters.Add(name_param);
     command.Parameters.Add(type_param);

     int rows = command.ExecuteNonQuery();
      
     Console.WriteLine("{0} rows updated", rows);
    }
 
    catch(CacheException e){}
 }

cnCache は、開いている CacheConnection オブジェクトを表します。

FeedbackOpens in a new tab