Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX -
Contents Index PreviousNext

Appendix G Sample C# .NET Programs> G.3 Advanced Applications

G.3.3 Delete Data Using Direct Access Key

The following is a sample program to delete data with the direct access key using the C# .NET.

mark1Data to be Deleted

<course>
  <id>0001</id>
  <name>Business negotiation</name>
  <instructor>
    <first-name>Max</first-name>
    <last-name>cameron</last-name>
  </instructor>
  <capacity>40</capacity>
  <current-auditors>30</current-auditors>
</course>

mark1Defined Direct Access Key

key /course/id/text()

mark1An Example of Using the APIs

The following is a sample program using the C# .NET.

using System;
using Fujitsu.Shunsaku;

class SampleDirectAccessDelete {
  static public void Main( string[] args ) {
    ShunService service = null;

    try {
      // Create ShunService
      service = new ShunService();

      // Connect Shunsaku by specifying the host name and port number
      service.Host = "DirSvr1";
      service.Port = 33101;
      service.ShunsakuFile = "shunsakuFile1";
      service.Connect();

      // Create ShunKeyRequirement object for deleting data
      ShunKeyRequirement keyReq = new ShunKeyRequirement();
      keyReq.KeyName = "key";

      // Add the direct access key of the data to be deleted
      keyReq.Records.Add( new ShunRecord() );
      keyReq.Records[0].Key = "0001";

      //Update course information
      service.DeleteByKey( keyReq );
      Console.WriteLine( "Deletion complete" );

      // Close the connection to Shunsaku
      service.Disconnect();

    }
    catch ( ShunContinuousException e ) {
      // Processing to perform if ShunContinuousException occurs
      try {
        if( service != null && service.State == ShunConnectionState.Open ) {
          service.Disconnect();
        }
      }
      catch ( ShunException ex ) {
        Console.WriteLine("Error message : {0}", ex.Message );
      }
      Console.WriteLine("Error message : {0}", e.Message );
    }
    catch ( ShunConnectionTerminatedException e ) {
      // Processing to perform if ShunConnectionTerminatedException occurs
      Console.WriteLine("Error message : {0}", e.Message );
    }
  }
}

mark1Execution Results

Deletion complete

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006