SetField modifies the value of a Field (that is, table column) in a Recordset to the supplied value.
Syntax
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 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. |
LPVARIANT | pv | Pointer to a COleVariant whose value will be inserted into the specified Field. |
Remarks
SetField is only available in dbDAO. It is provided as a more efficient way of setting the value of a Field, other than accessing the Recordset object's Fields collection, then invoking the SetValue method:
COleVariant vName(_T("Smith"), VT_BSTRT),
vValue(100, VT_I4);
...
recordset.Fields[_T("LastName")].SetValue(&vName);
recordset.Fields[0L].SetValue(&vValue);
Usage
#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