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.1 Adding Data

The following example shows how the VB .NET are used to add data.

mark1Data to be added

'I want to add an item of information about an Adelaide hotel (Hotel 9).'

Assemble the data to be added then add the data.

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 SampleInsert

  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 ShunRecordCollection for adding data
      Dim insertRecords As ShunRecordCollection = new ShunRecordCollection()

      '' Create ShunRecord for adding data
      Dim record As ShunRecord = new ShunRecord()

      '' Specifiy data
      record.Data = String.Concat( _
        "<document>", _
        "    <base>", _ 
        "        <name>Hotel 9</name>", _
        "        <city>Adelaide</city>", _
        "        <address>Belair, Adelaide</address>", _
        "        <detail>http://xxxxx.com.au</detail>", _
        "        <price>150</price>", _
        "    </base>", _
        "    <information>", _
        "        <date>2006/07/18</date>", _
        "    </information>", _
        "<note>No-smoking room with en-suite bathroom and toilet available, 5 minutes' walk to subway station XX</note>", _
        "</document>" )

      '' Add to the collection
      insertRecords.Add( record )

      '' Add data
      service.Insert( insertRecords )
      Console.WriteLine( "Addition complete" )

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

Addition complete

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006