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

Appendix H Sample VB .NET Programs> H.2 Updating Data

H.2.3 Updating Data

The following example shows how the VB .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 VB .NET.

Imports System
Imports Fujitsu.Shunsaku
Imports System.ComponentModel

Class SampleUpdate

  Shared Public Function Main( ByVal args() As String ) As Integer
    Dim service As ShunService = Nothing

    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
      Dim req As ShunSearchRequirement = 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
      Dim rs As ShunResultSet = service.Search( req )

      '' Create ShunRecordCollection for updating data
      Dim updateRecords As ShunRecordCollection = new ShunRecordCollection()

      '' Obtain the records that correspond to the search conditions
      For Each record As ShunRecord 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 )
        End If
      Next

      '' Update the data if the data was set successfully
      If updateRecords.Count > 0
        service.Update( updateRecords )
        Console.WriteLine( "Update complete" )

      End If

      '' Close the connection to Shunsaku
      service.Disconnect()
    
    Catch e As ShunContinuousException
      '' Processing to perform if ShunContinuousException occurs
      Try
        If Not service Is Nothing And service.State = ShunConnectionState.Open Then
          service.Disconnect()
        End If
      Catch ex As ShunException
        Console.WriteLine( "Error message : {0}", ex.Message )
      End Try
      Console.WriteLine( "Error message : {0}", e.Message )
    
    Catch e As ShunConnectionTerminatedException
      '' Processing to perform if ShunConnectionTerminatedException occurs
      Console.WriteLine( "Error message : {0}", e.Message )

    End Try
  End Function
End Class

mark1Execution Results

Update complete

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006