BOOL SetFieldData(int nField, LPCTSTR pszValue, CString* psWarning = NULL, BOOL bConvertMemo = TRUE);
nField
Specified a zero-based field index.
pszValue
Points to a null-terminated string which holds the data to be stored in the field.
psWarning
A pointer to a CString where SetFieldData will return a warning messages if an error occurred. Can be NULL.
bConvertMemo
TRUE if LONGBINARY data (typically Memo fields) should be handled like strings; FALSE if they should be ignored.
Call this method if you want to change field data in the current record.
You can use GetFieldData to dynamically fetch fields at run time. Use SetFieldData to change data in the current record.
If you have declared a CGXDynamicRecordset object, you can use GetFieldData to retrieve the field data and SetFieldData to change the data. The following sample code illustrates this case:
// Create a database object
CDatabase db;
// Create and open a recordset object
CGXDynamicRecordset rs( &db );
rs.SetSqlQuery( _T("Select * from student") );
rs.Open( );
// Loop through the recordset
rs.MoveFirst();
// Field 2 is "Grad Year"
// Increase "Grad Year" by 1
while (!rs.IsEOF())
{
CString s;
if (m_pQuerySet->GetFieldData(2, s))
{
_stprintf(s.GetBuffer(20), _T("%d"), _ttoi(s)+1);
s.ReleaseBuffer();
// switch to edit mode
m_pQuerySet->Edit();
// change values in the current record
m_pQuerySet->SetFieldData(2, s);
// update record
m_pQuerySet->Update();
} rs.MoveNext( );
}
rs.Close( );
db.Close( );
CGXDynamicRecordset::GetFieldData
Class Overview | Class Members