GetField returns the value of a Field (that is, a table column) in a Recordset. The Field is identified by either its name (that is, column name), or its index (that is, cardinal position in the row).
Syntax
COleVariantGetField( LPCTSTRpstrIndex );
COleVariantGetField( CString &str);
COleVariantGetField( LONGlIndex );
COleVariantGetField( COleVariant &vIndex);
Parameters
Type | Example | Description |
LPCTSTR | pstrIndex | A pointer to a string that contains the name of the desired Field. |
CString & | str | A reference to a CString that contains the name of the desired Field. |
LONG | lIndex | An integer that is the index of the desired Field, starting from the leftmost Field and counting from zero. |
COleVariant & | vIndex | A reference to a COleVariant with a value that is the index of the desired Field, starting from the leftmost Field and counting from zero, or a string containing the name of the Field. |
Remarks
GetField is only available in dbDAO. It is provided as a more efficient way of getting the value of a Field, other than accessing the Recordset object's Fields collection, then invoking the GetValue method:
COleVariant vValbyName, vValbyIndex;
vValbyName = recordset.Fields[_T("fieldname")].GetValue();
vValbyIndex = recordset.Fields[index].GetValue();
Usage
#include <afxole.h>
#include <dbdao.h>
COleVariant vVal;
// Initialize a recordset, etc.
// Get the value of the 'LastName' field.
vVal = recordset.GetField(_T("LastName"));
// Get the value of the third field.
vVal = recordset.GetField(2L);