Listing 3: Sample use of CColumns
UpdateDynaRowSet (int iRows, char* szUpdate)
{
CString WorkingString;
long RecordCount = 0;
CColumnInfo* pColInfo;
// NOTE: this assumes the RecordCount is set previous to
// entry to this function
// Move cursor back to previous row.
for ( RecordCount=0; RecordCount < iRows; RecordCount++ )
{
DynaRowSet->MovePrev();
if (DynaRowSet->IsBOF())
return FALSE;
}
// Now start moving forward, Editing as we go.
for ( RecordCount=0; RecordCount < iRows; RecordCount++ )
{
// Is Recordset empty?
if ( (DynaRowSet->IsEOF()) || (DynaRowSet->IsBOF()) )
{
LogError( "UpdateSQL(): No Rows found to Update!" );
return FALSE;
}
// Is it an updateable Recordset?
if (!DynaRowSet->CanUpdate())
{
LogError( "UpdateSQL(): Recordset is not Updateable!" );
return FALSE;
}
// Set recordset for Edit mode.
DynaRowSet->Edit();
// Get the first field of the record.
pColInfo = (CColumnInfo*)DynaRowSet->m_ColumnList.GetAt(0);
WorkingString = *(CString*) pColInfo->pData;
*(CString*) pColInfo->pData += szUpdate + " ";
// Dirty the field indicator so to force the Update().
DynaRowSet->SetFieldDirty((CString*) pColInfo->pData,TRUE)
;
// Attempt to update the row.
if (!DynaRowSet->Update())
{
LogError( "UpdateSQL(): Update failed!" );
return FALSE;
}
// Move to next record.
DynaRowSet->MoveNext();
}
return TRUE;
}
//End of File