ado 的 get_RecordCount 返回值总为-1 是何故??
我用下面的测试代码,发现不管记录数是多少get_RecordCount的返回总是-1,是怎么回事啊???
CString strConnection;
CString strSentence;
strConnection="DSN=xxx;uid=xxx;pwd=xxx";
strSentence="Select text from table1 where AutoId<10";
_Connection* pConnection;
HRESULT hr;
CoInitialize(NULL);
hr=CoCreateInstance(_uuidof(Connection),NULL,CLSCTX_ALL,_uuidof(_Connection),(void**)&pConnection);
BSTR bstrConnection=strConnection.AllocSysString();
hr=pConnection->Open(bstrConnection,NULL,NULL,0);
_Recordset* pRecordset;
hr=CoCreateInstance(_uuidof(Recordset),NULL,CLSCTX_ALL,_uuidof(_Recordset),(void**)&pRecordset);
hr=pRecordset->Open(_variant_t(strSentence),_variant_t((IDispatch*)pConnection,TRUE),adOpenForwardOnly,adLockOptimistic,-1);
hr=pRecordset->MoveFirst();
long l=0;
hr=pRecordset->get_RecordCount(&l);//l值总为 -1
VARIANT_BOOL b;
pRecordset->get_ADOEOF(&b);
while(b==VARIANT_FALSE)
{
pRecordset->MoveNext();
AfxMessageBox("ha");
pRecordset->get_ADOEOF(&b);
}
pRecordset->Close();
pConnection->Close();