Product Documentation

c-treeDB API for C# - Developers Guide

Previous Topic

Next Topic

Adding, Inserting or Deleting Fields

Fields are what hold the actual record data for each row in a table. Whereas a record could be considered a "row" in a table, a field could be considered a "column" in a table, or a "cell" in a record. The fields are defined at the time of the table creation.

Fields are added to the record definition in the order they are declared. The c-treeDB .NET API also includes a set of functions that will allow a field to be inserted at a certain place in the record definition and fields can also be deleted from the record definition.

Each field will have a file type (e.g., CT_INTEGER and CT_CHAR in the example below). For more information, see Field Types.

The CTTable.AddField() method will add a new field to the end of the record definition.

// create a new table object

CTTable ATable = new CTTable(ADatabase);


// add two fields to the table record definition

ATable.AddField("Field1", FIELD_TYPE.INTEGER, 4);

ATable.AddField("Field2", FIELD_TYPE.CHARS, 30);


// create the table

ATable.Create("MyTable", CREATE_MODE.NORMAL_CREATE);

Note: Delphi users should use the equivalent method CreateSession() instead of Create().

CTTable.InsertField() inserts a new field before a given field that has already been defined. The CTTable.InsertField() overloaded methods allow you to specify a field index or a field name to identify the position on the record definition that the new field will be inserted. The first field is number 0, the second field is number 1 and so on.

// create a new table object

CTTable ATable = new CTTable(ADatabase);


// add two fields to the table record definition

ATable.AddField( "Field1", FIELD_TYPE.INTEGER, 4);

ATable.AddField( "Field2", FIELD_TYPE.CHARS, 30);

ATable.InsertField("Field2", "Field3", FIELD_TYPE.BOOL, 1);


// create the table

ATable.Create("MyTable", CREATE_MODE.NORMAL_CREATE);

CTTable.DelField() deletes a field from the record definition. The CTTable.DelField() overloaded methods allow the user to specify a field index or a field name to identify the field to delete. The first field is number 0, the second field is number 1, and so on.

// create a new table object

CTTable ATable = new CTTable(ADatabase);


// add two fields to the table record definition

ATable.AddField( "Field1", FIELD_TYPE.INTEGER, 4);

ATable.AddField( "Field2", FIELD_TYPE.CHARS, 30);


// delete field2 from record definition

ATable.DelField("Field2");

// create the table

ATable.Create("MyTable", CREATE_MODE.NORMAL_CREATE);

TOCIndex