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.3 Advanced Applications

H.3.2 Searching Data Using Direct Access Key

The following is a sample program to search data with the direct access key using the VB .NET.

mark1Data to be Searched

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

mark1Defined Direct Access Key

key /course/id/text()

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 SampleDirectAccessSearch

  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 = "DirSvr1"
      service.Port = 33101
      service.ShunsakuFile = "shunsakuFile1"
      service.Connect()

      '' Create ShunKeyRequirement object for searching data
      Dim keyReq As ShunKeyRequirement = new ShunKeyRequirement()
      keyReq.KeyName = "key"

      '' Add the key to be searched
      keyReq.Records.Add( new ShunRecord() )
      keyReq.Records( 0 ).Key = "0001"

      '' Specify the search condition and execute the search
      Dim rs As ShunResultSet = service.SearchByKey( keyReq, "/" )

      '' Obtain the source information of the direct access key
      Console.WriteLine( "Number of hits  = {0}", rs.HitCount )
      Dim i As Integer = 0
      For Each record As ShunRecord In rs.Records
        i += 1
        Console.WriteLine( "[Result] Item No. {0}", i )
        Console.WriteLine( "Direct access key: {0}", record.Key )
        Console.WriteLine( "Data                :" )
        Console.WriteLine( record.Data )
      Next

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

Number of hits       = 1
[Result] Item No.1
Direct access key:0001
Data                :
<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>

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006