Product Documentation

c-treeDB API for VB.Net

Previous Topic

Next Topic

Manage

Manage() provides data management functionality for your application and/or process.

Below is the code for Manage():

'

' Manage()

'

' This function performs record adds and updates using locking

'

Sub Manage()

Console.WriteLine("MANAGE")

' populate the table with data

Add_CustomerMaster_Records()

' display contents of table

Display_Records()

' update a record under locking control

Update_CustomerMaster_Record()

' display again after update and effects of lock

Display_Records()

End Sub

'

' Add_CustomerMaster_Records()

'

' This function adds records to table CustomerMaster from an

' array of strings

'

Public Structure CUSTOMER_DATA

' struct members

Public number, zipcode, state, rating, name, address, city As String

' struct constructor

Public Sub New(ByVal number As String, ByVal zipcode As String, ByVal state As String, ByVal rating As String, ByVal name As String, ByVal address As String, ByVal city As String)

Me.number = number

Me.zipcode = zipcode

Me.state = state

Me.rating = rating

Me.name = name

Me.address = address

Me.city = city

End Sub

End Structure

Sub Add_CustomerMaster_Records()

Dim data(3) As CUSTOMER_DATA

data(0) = New CUSTOMER_DATA("1000", "92867", "CA", "1", "Bryan Williams", "2999 Regency", "Orange")

data(1) = New CUSTOMER_DATA("1001", "61434", "CT", "1", "Michael Jordan", "13 Main", "Harford")

data(2) = New CUSTOMER_DATA("1002", "73677", "GA", "1", "Joshua Brown", "4356 Cambridge", "Atlanta")

data(3) = New CUSTOMER_DATA("1003", "10034", "MO", "1", "Keyon Dooling", "19771 Park Avenue", "Columbia")

Dim nRecords As Integer = data.Length

Delete_Records(MyRecord)

Console.WriteLine(ControlChars.Tab + "Add records...")

Try

Dim i As Integer

For i = 0 To nRecords - 1

MyRecord.Clear()

' populate record buffer with data

MyRecord.SetFieldAsString(0, data(i).number)

MyRecord.SetFieldAsString(1, data(i).zipcode)

MyRecord.SetFieldAsString(2, data(i).state)

MyRecord.SetFieldAsString(3, data(i).rating)

MyRecord.SetFieldAsString(4, data(i).name)

MyRecord.SetFieldAsString(5, data(i).address)

MyRecord.SetFieldAsString(6, data(i).city)

' add record

MyRecord.Write()

Next

Catch E As CTException

Handle_Exception(E)

End Try

End Sub

'

' Delete_Records()

'

' This function deletes all the records in the table

'

Sub Delete_Records(ByVal record As CTRecord)

Dim found As Boolean

Console.WriteLine(ControlChars.Tab + "Delete records...")

Try

' enable session-wide lock flag

MySession.Lock(LOCK_MODE.WRITE_BLOCK_LOCK)

' read first record

found = record.First()

While (found) ' while records are found

' delete record

record.Delete()

' read next record

found = record.Next()

End While

' reset session-wide locks

MySession.Unlock()

Catch E As CTException

Handle_Exception(E)

End Try

End Sub

'

' Display_Records()

'

' This function displays the contents of a table. First() and Next()

' fetch the record. Then each field is parsed and displayed

'

Sub Display_Records()

Dim found As Boolean

Dim custnumb As String

Dim custname As String

Console.Write(ControlChars.Tab + "Display records...")

Try

' read first record

found = MyRecord.First()

While (found)

custnumb = MyRecord.GetFieldAsString(0)

custname = MyRecord.GetFieldAsString(4)

Console.WriteLine(ControlChars.NewLine + ControlChars.Tab + ControlChars.Tab + "{0,-8}{1,-20}", custnumb, custname)

' read next record

found = MyRecord.Next()

End While

Catch E As CTException

Handle_Exception(E)

End Try

End Sub

'

' Update_CustomerMaster_Records()

'

' Update one record under locking control to demonstrate the effects

' of locking

'

Sub Update_CustomerMaster_Record()

Console.WriteLine(ControlChars.Tab + "Update Record...")

Try

' enable session-wide lock flag

MySession.Lock(LOCK_MODE.WRITE_BLOCK_LOCK)

MyRecord.Clear()

MyRecord.SetFieldAsString(0, "1003")

' find record by customer number

If (MyRecord.Find(FIND_MODE.EQ)) Then

MyRecord.SetFieldAsString(4, "KEYON DOOLING")

' rewrite record

MyRecord.Write()

Console.WriteLine(ControlChars.Tab + "Press <ENTER> key to unlock")

Console.ReadLine()

End If

' reset session-wide locks

MySession.Unlock()

Catch E As CTException

Handle_Exception(E)

End Try

End Sub

TOCIndex