Product Documentation

c-treeDB API for C# - Developers Guide

Previous Topic

Next Topic

Creating a Table Object Without Database Support

It is possible to create or open a table without database support by passing a session object when creating the table object.

// create the session and table objects

CTSession ASession = new CTSession(SESSION_TYPE.CTDB_SESSION);

CTTable ATable = new CTTable(ASession);


// logon to session

ASession.Logon("FAIRCOMS", "ADMIN", "ADMIN");


// without database support, it is necessary to

// specify the path were the table is located

ATable.SetPath("C:\\MyDocuments");


// open the table

try

{

ATable.Open("MyTable", OPEN_MODE.NORMAL_OPEN);

}

catch (CTException err)

{

Console.Write("Table open failed with error {0}\n, err.GetErrorCode());

}

Please note from the code above the need to specify the path where the table is located. If no path is specified, c-treeDB .NET will try to open the table from the current directory. The same principle applies when creating a table without database support:

// create the session and table objects

CTSession ASession = new CTSession(SESSION_TYPE.CTDB_SESSION);

CTTable ATable = new CTTable(ASession);


// logon to session

ASession.Logon("FAIRCOMS", "ADMIN", "ADMIN");

// add fields to table

ATable.AddField("Field1", FIELD_TYPE.INT2, 2);

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


// without database support, it is necessary to

// specify the path were the table is located

ATable.SetPath("C:\\MyDocuments");


// open the table

try

{

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

}

catch (CTException err)

{

Console.Write("Create open failed with error {0}\n, err.GetErrorCode());

}

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

TOCIndex