ページの先頭行へ戻る
Interstage Shunsaku Data Manager V9.0.6 アプリケーション開発ガイド
FUJITSU Software

H.2.3 データを更新する

データを更新する場合の、VB .NETの使用例を示します。


検索条件

「2006年7月18日に神奈川で宿泊可能なホテルのうち、ホテル1の情報を更新したい。」

年月日(2006年7月18日)を条件に検索を行い、ホテル名『ホテル1』と一致したデータを更新します。


APIの使用例


以下に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
      '' ShunService の作成
      service = new ShunService()

      '' ホスト名 ポート番号を指定して Shunsaku に接続
      service.Host = "DirSrv1"
      service.Port = 23101
      service.Connect()

      '' ShunSearchRequirement の作成
      Dim req As ShunSearchRequirement = new ShunSearchRequirement()

      '' 各種検索条件の設定
      req.QueryExpression = "/document/base/name == 'ホテル1'"
      req.ReturnExpression = "/document/base/name/text()"
      req.ReplyNumber = 1
      req.RequestCount = 30

      '' 検索条件を指定して検索を実行
      Dim rs As ShunResultSet = service.Search( req )

      '' 更新用 ShunRecordCollection を作成
      Dim updateRecords As ShunRecordCollection = new ShunRecordCollection()

      '' 検索条件に該当するレコードを取得
      For Each record As ShunRecord In rs.Records
        If record.Data = "ホテル1"
          '' ホテル1の情報について、レコードID、更新データを設定
          record.Data = String.Concat( _
            "<document>", _
            "    <base>", _
            "        <name>ホテル1</name>", _
            "        <prefecture>大阪</prefecture>", _
            "        <address>大阪府大阪市中央区</address>", _
            "        <detail>http:''xxxxx.co.jp</detail>", _
            "        <price>8000</price>", _
            "    </base>", _
            "    <information>", _
            "        <date>2006年07月18日</date>", _
            "    </information>", _
            "    <note>バス付 トイレ付 地下鉄 △△駅徒歩02分</note>", _
            "</document>" )
          updateRecords.Add( record )
        End If
      Next

      '' データ設定に成功している場合、データを更新
      If updateRecords.Count > 0
        service.Update( updateRecords )
        Console.WriteLine( "更新終了" )

      End If

      '' Shunsaku から切断
      service.Disconnect()
    
    Catch e As ShunContinuousException
      '' ShunContinuousExceptionが発生した場合の処理を記述
      Try
        If Not service Is Nothing And service.State = ShunConnectionState.Open Then
          service.Disconnect()
        End If
      Catch ex As ShunException
        Console.WriteLine( "エラーメッセージ : {0}", ex.Message )
      End Try
      Console.WriteLine( "エラーメッセージ : {0}", e.Message )
    
    Catch e As ShunConnectionTerminatedException
      '' ShunConnectionTerminatedExceptionが発生した場合の処理を記述
      Console.WriteLine( "エラーメッセージ : {0}", e.Message )

    End Try
  End Function
End Class

実行結果


更新終了