Skip to main content

An Insert

The following method inserts a row into the Contact table. It uses CacheCommand and two CacheParameter instances: one representing Name and the other 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){}
 }

Note that cnCache represents an open CacheConnection object.

FeedbackOpens in a new tab