GetField returns the value of a CdbField (that is, a table column) in a Recordset. The CdbField is identified by either its name (that is, column name), or its index (that is, cardinal position in the row).
Syntax: GetField
COleVariantGetField( LPCTSTRpstrIndex );
COleVariantGetField( CString &str );
COleVariantGetField( LONGlIndex );
COleVariantGetField( COleVariant &vIndex );
Syntax: SetField
VOIDSetField( LPCTSTR pstrIndex, LPVARIANT pv );
VOIDSetField( CString &str,LPVARIANT pv );
VOIDSetField( LONG lIndex, LPVARIANT pv );
VOIDSetField( COleVariant &vIndex,LPVARIANT pv );
Parameters
Type | Example | Description |
LPCTSTR | pstrIndex | A pointer to a string that contains the name of the desired CdbField. |
CString & | str | A reference to a CString that contains the name of the desired CdbField. |
LONG | lIndex | An integer that is the index of the desired CdbField, starting from the leftmost CdbField and counting from zero. |
COleVariant & | vIndex | A reference to a COleVariant with a value that is the index of the desired CdbField, starting from the leftmost CdbField and counting from zero, or a string containing the name of the CdbField. |
LPVARIANT | pv | Pointer to a COleVariant whose value will be inserted into the specified CdbField. |
Remarks
GetField and SetField are only available in dbDAO. They are provided as a more efficient way of getting or setting the value of a CdbField, other than accessing the CdbRecordset object's Fields collection, then using the GetValue or SetValue properties:
COleVariant vValbyName, vValbyIndex;
vValbyName = recordset.Fields[_T("fieldname")].GetValue();
vValbyIndex = recordset.Fields[index].GetValue();
COleVariant vName(_T("Smith"), VT_BSTRT),
vValue(100, VT_I4);
...
recordset.Fields[_T("LastName")].SetValue(&vName);
recordset.Fields[0L].SetValue(&vValue);
Usage: GetField
#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);
Usage: SetField
#include <afxole.h>
#include <dbdao.h>
COleVariant vName(_T("Smith"), VT_BSTRT),
vValue(100, VT_I4);
...
recordset.SetField(_T("LastName"), &vName); // set the LastName field
recordset.SetField(0L, &vValue); // set the first field