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 simple record functions of add, delete and gets

'

Sub Manage()

Console.WriteLine("MANAGE")

' delete any existing records

Delete_Records()

' populate the table with data

Add_Records()

' display contents of table

Display_Records()

End Sub

'

' Delete_Records()

'

' This function deletes all the records in the table

'

Sub Delete_Records()

Dim found As Boolean

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

Try

' read first record

found = MyRecord.First()

While (found) ' while records are found

' delete record

MyRecord.Delete()

' read next record

found = MyRecord.Next()

End While

Catch E As CTException

Handle_Exception(E)

End Try

End Sub

'

' Add_Records()

'

' This function adds records to a table in the database from an

' array of strings

'

Public Structure DATA_RECORD

' 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_Records()

Dim data(3) As DATA_RECORD

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

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

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

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

Dim nRecords As Integer = data.Length

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

'

' 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

TOCIndex