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

付録H VB .NET サンプルプログラム> H.3 拡張的なアプリケーション

H.3.3 ダイレクトアクセスキーを使用してデータを削除する

ダイレクトアクセスキーを使用してデータを削除する場合のVB .NETの使用例を示します。

■削除するデータ

<course>
  <id>0001</id>
  <name>Business negotiation</name>
  <instructor>
    <first-name>Max</first-name>
    <last-name>cameron</last-name>
  </instructor>
  <capacity>40</capacity>
  <current-auditors>30</current-auditors>
</course>

■定義したダイレクトアクセスキー

key /course/id/text()

■APIの使用例

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

Imports System
Imports Fujitsu.Shunsaku
Imports System.ComponentModel

Class SampleDirectAccessDelete

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

    Try
      '' ShunService の作成
      service = new ShunService()

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

      '' 削除用の ShunKeyRequirement オブジェクトを作成
      Dim keyReq As ShunKeyRequirement = new ShunKeyRequirement()
      keyReq.KeyName = "key"

      '' 削除したいデータのダイレクトアクセスキーを追加
      keyReq.Records.Add( new ShunRecord() )
      keyReq.Records( 0 ).Key = "0001"

      ''コース情報の更新
      service.DeleteByKey( keyReq )
      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