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

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

mark1Search Conditions

'Of the hotels in Sydney that have a vacancy on 2006/07/18, I want to update the information relating to Hotel 1.'

Perform a search using the date (2006/07/18) as the search condition, then update data whose name matches "Hotel 1".

mark1An Example of Using the APIs

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

using System;
using Fujitsu.Shunsaku;

class SampleUpdate {
  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 = "DirSrv1";
      service.Port = 33101;
      service.Connect();

      // Create ShunSearchRequirement 
      ShunSearchRequirement req = new ShunSearchRequirement();

      // Set each type of search conditions
      req.QueryExpression = "/document/base/name == 'Hotel 1'";
      req.ReturnExpression = "/document/base/name/text()";
      req.ReplyNumber = 1;
      req.RequestCount = 30;

      // Specify the search condition and execute the search
      ShunResultSet rs = service.Search( req );

      // Create ShunRecordCollection for updating data
      ShunRecordCollection updateRecords = new ShunRecordCollection();

      // Obtain the records that correspond to the search conditions
      foreach ( ShunRecord record in rs.Records ) {
        if ( record.Data == "Hotel 1" ) {
          // Set the record ID and data to update for Hotel 1 information
          record.Data = String.Concat(
            "<document>",
            "    <base>",
            "        <name>Hotel 1</name>",
            "        <city>Sydney</city>",
            "        <address>Bondi Beach</address>",
            "        <detail>http://xxxxx.com.au</detail>",
            "        <price>300</price>",
            "    </base>",
            "    <information>",
            "        <date>2006/07/18</date>",
            "    </information>",
            "    <note>En-suite bathroom and toilet, two minutes' walk to train station XX</note>",
            "</document>" );
          updateRecords.Add( record );
        }
      }

      // Update the data if the data was set successfully
      if ( updateRecords.Count > 0 ) {
        service.Update( updateRecords );
        Console.WriteLine( "Update 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

Update complete

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006