Mastering DataGate File Adapter Class

Estimated reading time: 2 minutes

The ASNA.DataGate.Client.FileAdapter class is the entry point for data access in DG. FileAdapter consists of a reference to an AdgConnection object and a set of path strings naming the database file being accessed. FileAdapter methods allow the standard set of access functions including reading, writing, updating, and deleting file records. It also contains several properties defining constraints on the access to be performed on the file. These properties, such as the AccessMode property, should be set prior to opening the file.

FileAdapter employs an AdgDataSet object for data exchange with the database. Thus when a file is opened, you specify an AdgDataSet to subsequently be used with the opened file.

The following AVR code opens a database connection and then creates a FileAdapter object to be used for reading records from a file.

  ASNA.DataGate.Client;
  ASNA.DataGate.Common;
  ...
  AdgConnection Cx;
  FileAdapter DbFile;
  AdgDataSet Ds;
  Cx = new AdgConnection("ASNA Local DB");
  Cx.Open();
  DbFile = new FileAdapter(Cx,"/cmmaster","*first");
  DbFile.AccessMode = AccessMode.Read;
  DbFile.OpenNewAdgDataSet(ref Ds);

FileAdapter models an open database file’s “pointer”, or the current position of the virtual record cursor on the database server. For example, FileAdapter’s OpenNewAdgDataSet method sets the record cursor to just prior to the first record in the file. FileAdapter also includes “seek” methods, used to place the record cursor to positions of particular interest. The CurrentFormatIndex, FormatRequested, RRN, and ExactSeek properties of FileAdapter provide indicators of the current position of the record cursor.

See Also

AdgConnection Class
AdgDataSet Class
FileAdapter Class
FileAdapter Class Members
Database File Records and AdgDataSet
Efficient File Access
Reading and Writing to Database Files
Verifying Results with Exception Handling