PRB: C2664 Error When Using CNoAccessorID: Q190981
|
Using the CNoAccessor class as a template argument for CCommand or CTable causes the following error:
For example, the following code causes the error to occur:atldbcli.h(2819) : error C2664: 'SetAccessor' : cannot convert parameter 1 from 'class ATL::CAccessorRowset<class ATL::CNoAccessor,class ATL::CRowset> *const ' to 'class ATL::CAccessorBase *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
CCommand<CNoAccessor>
The second argument of the CCommand<> or CTable<> template is the rowset class. By default, this is set to CRowset. The CRowset class assumes that there will be an accessor used. Therefore, it is necessary to specify CNoRowset or some other user-defined rowset class that doesn't rely on an accessor.
To use CNoAccessor, specify "CNoRowset" for the rowset class argument of
the CCommand or CTable template classes.
The code resembles the following:
CCommand<CNoAccessor, CNoRowset>
If, for some reason, you need to specify CNoAccessor but still want some of
the functionality of the CRowset class, derive a new class from CRowset and
override any functions that rely on an accessor.
This behavior is by design.
Below is an example of how you might use the CNoAccessor class:
#include <atlbase.h>
#include <atldbcli.h>
int main(int argc, char* argv[])
{
CoInitialize(NULL);
CDataSource ds;
CSession sn;
ds.OpenFromInitializationString(
L"Provider=MSDASQL;Data Source=AccessDB");
sn.Open(ds);
CCommand<CNoAccessor, CNoRowset> cmd;
CDBPropSet ps(DBPROPSET_ROWSET);
ps.AddProperty(DBPROP_IRowsetChange, true);
ps.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_DELETE);
cmd.Open(sn, "INSERT INTO Table1 VALUES('Col1Value',
'Col2Value'", &ps , NULL, DBGUID_DBSQL, false);
// No returned results so need to bind anything
cmd.Close();
return 0;
}
Additional query words: kbvc600 kbTemplate kbOLEDB
Keywords : kbtemplate kbOLEDB kbVC600
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: July 26, 1999