Product Documentation

c-treeDB API for C#

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

//

static void Manage()

{

Console.WriteLine("MANAGE");

// delete any existing records

Delete_Records();

// populate the table with data

Add_Records();

// display contents of table

Display_Records();

}

//

// Delete_Records()

//

// This function deletes all the records in the table

//

static void Delete_Records()

{

bool found;

Console.WriteLine("\tDelete records...");

try

{

// read first record

found = MyRecord.First();

while (found) // while records are found

{

// delete record

MyRecord.Delete();

// read next record

found = MyRecord.Next();

}

}

catch(CTException E)

{

Handle_Exception(E);

}

}

//

// Add_Records()

//

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

// array of strings

//

public struct DATA_RECORD

{

// struct members

public string number, zipcode, state, rating, name, address, city;

// struct constructor

public DATA_RECORD(string number, string zipcode, string state, string rating, string name, string address, string city)

{

this.number = number;

this.zipcode = zipcode;

this.state = state;

this.rating = rating;

this.name = name;

this.address = address;

this.city = city;

}

};

static void Add_Records()

{

DATA_RECORD[] data = new DATA_RECORD[4];

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");

int nRecords = data.Length;

Console.WriteLine("\tAdd records...");

try

{

for(int i = 0; i < nRecords; i++)

{

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();

}

}

catch(CTException E)

{

Handle_Exception(E);

}

}

//

// Display_Records()

//

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

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

//

static void Display_Records()

{

bool found;

string custnumb;

string custname;

Console.Write("\tDisplay records...");

try

{

// read first record

found = MyRecord.First();

while (found)

{

custnumb = MyRecord.GetFieldAsString(0);

custname = MyRecord.GetFieldAsString(4);

Console.WriteLine("\n\t\t{0,-8}{1,-20}", custnumb, custname);

// read next record

found = MyRecord.Next();

}

}

catch(CTException E)

{

Handle_Exception(E);

}

}

TOCIndex