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.2 Deleting Data

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

'I want to delete the data relating to Hotel 9 from the hotels in Adelaide that have a vacancy on 2006/07/18.'

Perform a search using the date (2006/07/18) and location (Adelaide) as conditions, then delete data whose name matches "Hotel 9".

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 SampleDelete

  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 ShunSearchRequirement
      Dim req As ShunSearchRequirement = new ShunSearchRequirement()

      '' Set each type of search conditions
      req.QueryExpression = "/document/base/city == 'Adelaide' AND /document/information/date == '2006/07/18'"
      req.ReturnExpression = "/document/base/name/text()"
      req.ReplyNumber = 1
      req.RequestCount = 30

      '' Specify the search condition and execute the search
      Dim rs As ShunResultSet = service.Search( req )

      '' Create ShunRecordCollection for deleting data
      Dim deleteRecords As ShunRecordCollection = new ShunRecordCollection()

      '' Obtain the record of Hotel 9
      For Each record As ShunRecord In rs.Records
        If record.Data = "Hotel 9"
          deleteRecords.Add( record )
        End If
      Next

      '' Delete the data if acquisition of the corresponding record is successful
      If deleteRecords.Count > 0
        service.Delete( deleteRecords )
        Console.WriteLine( "Deletion complete" )
      End If

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

Deletion complete

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006