1つのトランザクションを扱う.NET APIの場合の記述例について、以下に示します。
| /*
 * 以下のように用意されていることを仮定しています。
 *  sPerson :追加したい従業員の情報
 *  sQuery :検索式を格納した文字列
 *  sReturn :リターン式を格納した文字列
 *  updateData :更新データを格納した文字列
 */
// ShunServiceオブジェクトを作成
// 接続先のホスト名:DirSvr1
// ポート番号:23101
// Shunsaku File名: fileA
ShunService service = new ShunService();
service.Host = "DirSvr1";
service.Port = 23101;
service.ShunsakuFile = "fileA";
service.Connect();
// 自動コミットを無効に設定
service.AutoCommit = false;
ShunRecordCollection insertRecords = new ShunRecordCollection();
ShunRecord personRecord = new ShunRecord( sPerson );
insertRecords.Add( personRecord );
// データ追加
service.Insert( insertRecords );
//接続先のShunsaku FileをfileDに切替え
service.ChangeShunsakuFile("fileD");
ShunSearchRequirement req = new ShunSearchRequirement();
req.QueryExpression = sQuery;
req.ReturnExpression = sReturn;
// 更新用のデータを検索
ShunResultSet rs = service.Search( req );
ShunRecord updateRecord = null;
foreach ( ShunRecord record in rs.Records ) {
  updateRecord = record;
}
updateRecord.Data = updateData;
ShunRecordCollection updateRecords = new ShunRecordCollection();
updateRecords.Add( updateRecord );
//データ更新
service.Update( updateRecords );
// ここまでの更新をコミット
service.Commit();
service.Disconnect(); |