Environment: VC6 SP4, NT4 SP6
Acknowledgements
This article is based in part on Bob Place’s
ADO is AOK (a simple ADO tutorial).
Wrapper Usage
This is consist of 2 classes.
- CDyndb : This Class manages connections and recordsets. Recordsets are organized as linked list (CList) and you can access them using their ids.
- CDynRec : This class is the node to populate for each recordsets.
Simply follow these steps in order to use the ADO wrapper classes:
- You need to add the following line stdafx.h :
- Call the OpenConn function
theApp.m_dyndb.OpenConn(“driver=sql server;server=dogu;UID=sa;PWD=;database=dbtraining;”); - Call OpenRec function
- Call GetFieldVal function to get the value of the fields. This function returns variant type.
You can cast it as usual way like “short(variantdata);” - Call GetFieldType to get the type of the field. “en” has a definition like
DataTypeEnum en; (see MSDN for details) - Call GetFieldCount to get the number of the fields that selected in the recordset.
- Call GetFieldName to obtain the name of the field.
#import "c:program filescommon filessystemadomsado21.tlb" no_namespace rename ("EOF", "adoEOF")
theApp.m_dyndb.OpenRec("select * from Courses");
vardat=theApp.m_dyndb.GetFieldVal(0,2);
en=theApp.m_dyndb.GetFieldType(0,2);
To iterate through a recordset, you can use the m_pRecordSet member functions MoveXXX.