Working with fileds
Previous  Index  Next

OraField class is generally an encapsulation for the values contained in a single field of a recordset. You get access to the fields when you have executed an SQL or PL/SQL statement which returns recordset.
Immediately after opening a recordset all its fields hold the first record values. To instruct recordset object to fetch other record or even jump to a specific record you may use navigational methods of CRDataset class which is an ancestor of the OraRecordset class. To get or set individual fields for the record you may use methods provided by OraField class. For example, given the following code that retrieves records from the Dept table:

  OraConnection connection("scott/tiger@ora");
  OraCommand cmd(connection);
  cmd.setCommandText("SELECT * FROM Dept");

  OraRecordset& rs = cmd.executeQuery();

you may now use a field member function to get access to the fields of current record. You have to provide either the field name or its index. For example, you can write this code to get the value of DNAME field:

  name = rs.field("DNAME").getString();

or to get integer value of the first field:

  num = rs.field(1).getInt();

To assign new values to the fields of the record use set-methods. For example:

  rs.field("DNAME").setString("Marketing);
  rs.field(1).setInt(10000);

See Also

OraRecordset


OCL | Using OCL | Index