Product Documentation

c-treeDB API for C# - Developers Guide

Previous Topic

Next Topic

Finding Records

You can search for records in a table using one of the CTRecord.Find(), CTRecord.FindTarget() and CTRecord.FindRowid() methods. c-treeDB .NET performs the find operations against the table indexes. When an index entry is found, the record data is loaded into the record buffer.

Before you can call CTRecord.Find(), you need to prepare the data you want to find:

  1. Clear a record buffer
  2. Set the default index with the appropriate value
  3. Populate the fields that make up the index segment
  4. Call CTRecord.Find() with the appropriate find mode


// find record with product code of DISKETTE

CTRecord ARecord = new CTRecord(ATable);


// clear the record buffer

ARecord.Clear();


// set the default index to "MyIndex"

ARecord.SetDefaultIndex("MyIndex");


// populate the 'product' field

ARecord.SetFieldAsString("product", "DISKETTE");


// find the record

try

{

if (ARecord.Find(FIND_MODE.EQ))

Console.Write("Record found\n");

else

Console.Write("Record not found\n");

}

catch (CTException err)

{

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

}


CTRecord.Find(), CTRecord.FindTarget() and CTRecord.FindRowid() return true if the record was found or false if the record was not found. These methods throw an exception if an error occurs.

TOCIndex