ADO中关于记录集函数GetRecordCount()返回-1的问题
程序刚开始采用Sqlserver验证方式。
_ConnectionPtr m_pConn;
CString strCon;
连接数据库
strCon="driver={SQL Server};Server=(local);DATABASE=test;UID=sa;PWD=sa";
hr=m_pConn->Open(_bstr_t(strCon),"","",adModeUnknown);
采用windows验证方式
strCon="Provider=SQLOLEDB.1; Integrated Security=SSPI;Persist Security Info=False; Data Source=(local);Initial Catalog=test";
hr=m_pConn->Open(_bstr_t(strCon),"","",adModeUnknown);
使用该连接 查询记录
_RecordsetPtr pRst;
pRst.CreateInstance(__uuidof(Recordset));
pRst->Open((_variant_t)sql,_variant_t((IDispatch*)m_pConn,true),adOpenStatic,adLockOptimistic,adCmdText);
int iRecordCount=pRst->GetRecordCount();
当采用Sqlserver验证方式登录时,返回的记录集有记录。而当采用windows方式登录时里面的记录为-1.
。是什么原因导致?
我看到将记录集在Open之前添加
pRst->CursorType = adOpenStatic;
pRst->CursorLocation = adUseClient;
可以返回 ,是否确保返回的结果值正确?谢谢