データを追加する場合のVB .NETの使用例を示します。
「神奈川のホテル情報(ホテル9の情報)を1件追加したい。」
追加したいデータを組み立て、データを追加します。
以下に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 = 23101 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 |
追加終了