Microsoft KB Archive/190981

= PRB: C2664 Error When Using CNoAccessor =

Article ID: 190981

Article Last Modified on 3/2/2005

-

APPLIES TO

 Microsoft OLE DB 2.7, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q190981

<div class="symptoms_section">

SYMPTOMS
Using the CNoAccessor class as a template argument for CCommand or CTable causes the following error:

<pre class="fixed_text">  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

For example, the following code causes the error to occur: CCommand<CNoAccessor> cmd;

<div class="cause_section">

CAUSE
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.

<div class="resolution_section">

RESOLUTION
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.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
Below is an example of how you might use the CNoAccessor class: #include <atlbase.h>  #include <atldbcli.h>

int main(int argc, char* argv[]) {  HRESULT hr; CoInitialize(NULL);

CDataSource ds; CSession sn; hr = ds.OpenFromInitializationString(                    L"Provider=MSDASQL;Data Source=YourDSN"); hr = sn.Open(ds);

CCommand<CNoAccessor, CNoRowset> cmd; CDBPropSet ps(DBPROPSET_ROWSET); ps.AddProperty(DBPROP_IRowsetChange, true); ps.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_DELETE); hr = 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; }

Keywords: kbconsumer kbdatabase kbtemplate kbprb kbdtl kbmdacnosweep KB190981

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.