Interstage Shunsaku Data Manager アプリケーション開発ガイド - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX共通 -
目次 索引 前ページ次ページ

付録H VB .NET サンプルプログラム> H.2 データの更新

H.2.1 データを追加する

データを追加する場合のVB .NETの使用例を示します。

■追加するデー

「神奈川のホテル情報(ホテル9の情報)を1件追加したい。」

追加したいデータを組み立て、データを追加します。

■APIの使用

以下にVB .NETを使用したプログラミング例を示します。

Imports System
Imports Fujitsu.Shunsaku
Imports System.ComponentModel

Class SampleInsert

  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 = 33101
      service.Connect()

      '' 追加用 ShunRecordCollection を作成
      Dim insertRecords As ShunRecordCollection = new ShunRecordCollection()

      '' 追加用 ShunRecord を作成
      Dim record As ShunRecord = new ShunRecord()

      '' データを指定
      record.Data = String.Concat( _
        "<document>", _
        "    <base>", _ 
        "        <name>ホテル9</name>", _
        "        <prefecture>新横浜</prefecture>", _
        "        <address>神奈川県横浜市神奈川区</address>", _
        "        <detail>http://xxxxx.co.jp</detail>", _
        "        <price>6000</price>", _
        "    </base>", _
        "    <information>", _
        "        <date>2006年07月18日</date>", _
        "    </information>", _
        "<note>バス付 トイレ付 禁煙ルーム選択可 地下鉄 **駅徒歩05分</note>", _
        "</document>" )

      '' コレクションに追加
      insertRecords.Add( record )

      '' データを追加
      service.Insert( insertRecords )
      Console.WriteLine( "追加終了" )

      '' 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

■実行結

追加終了

目次 索引 前ページ次ページ

All Rights Reserved, Copyright(C) 富士通株式会社 2006