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.2 Updating Data

G.2.1 Adding Data

The following example shows how the C# .NET are used to add data.

mark1Data to be added

'I want to add an item of information about an Adelaide hotel (Hotel 9).'

Assemble the data to be added then add the data.

mark1An Example of Using the APIs

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

using System;
using Fujitsu.Shunsaku;

class SampleInsert {
  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.Connect();

      // Create ShunRecordCollection for adding data
      ShunRecordCollection insertRecords = new ShunRecordCollection();

      // Create ShunRecord for adding data
      ShunRecord record = new ShunRecord();

      // Specify data
      record.Data = String.Concat(
        "<document>",
        "    <base>",
        "        <name>Hotel 9</name>",
        "        <city>Adelaide</city>",
        "        <address>Belair, Adelaide</address>",
        "        <detail>http://xxxxx.com.au</detail>",
        "        <price>150</price>",
        "    </base>",
        "    <information>",
        "        <date>2006/07/18</date>",
        "    </information>",
        "<note>No-smoking room with en-suite bathroom and toilet available, 5 minutes' walk to subway station XX</note>",
        "</document>" );

      // Add to the collection
      insertRecords.Add( record );

      // Add data
      service.Insert( insertRecords );
      Console.WriteLine( "Addition 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

Addition complete

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006