ADODB::_RecordsetPtr::GetRecordCount() failure
ADODB::_RecordsetPtr::GetRecordCount() failure
我正在尝试使用ADO在C++中执行一些查询。这是我的代码
string commandline = "SELECT * FROM My_Table";
ADODB::_RecordsetPtr pRS("ADODB.Recordset");
ADODB::_ConnectionPtr pConn("ADODB.Connection");
pRS->Open(commandline.c_str(), _variant_t((IDispatch *) pConn, true), ADODB::adOpenUnspecified, ADODB::adLockUnspecified, ADODB::adCmdText);
cout<<pRS->GetRecordCount();
我在My_Table
中有1000条记录,因此我希望看到输出1000
。但是,输出是-1
。
我能知道我做错了什么吗?
非常感谢。
RecourdCount
属性只有在底层提供程序或游标类型实际支持的情况下才有效,否则返回-1。
尝试使用静态光标(传递ADODB::adOpenStatic
而不是ADODB::adOpenUnspecified
)
还请注意,即使提供程序支持,获取记录计数也可能会占用大量资源,因为提供程序必须先获取所有记录,然后才能知道受查询影响的记录数。
有关详细文档,请参阅此MSDN页面。
相关文章:
- 为什么我会收到"Run-Time Check Failure #2 - Stack around the variable 'pr' was corrupted"错误?
- 实现多类型算术运算符时如何解决"template argument deduction/substitution failure"
- Failure for Gdiplus::Bitmap::FromHICON
- 如何在Visual Studio中查看static_assert 'failure source'?
- 调用 dll 函数时"Run-Time Check Failure #0 - The value of ESP"
- C++ 异常处理:异常与 ifstream::failure
- 动态数组"error code unspecified launch failure"
- C++指向对象删除的指针数组,"Debug assertion failure!"
- 为什么 getline() 在异常掩码未设置为 eofbit 时抛出'std::ios_base::failure'?
- "candidate template ignored: substitution failure:"编译器错误?
- Cython C++ 未定义对 std::ios_base::failure 的引用
- CreateCompatibleDC() failure
- ADODB::_RecordsetPtr::GetRecordCount() failure
- Catch-ios::failure保持循环
- 抛出 what() 的实例后调用的终止 'std::ios_base::failure': 基本
- Failure to find MyClass.cpp
- c++ Inline Function throw Exception: Run-Time Check Failure
- OpenProcess Failure (SeDebugPrivilege?)
- 相当于 "bool DllMain()" 的 c/c++ Linux - 但我需要将 failure 返回给 dlopen()
- c++ 收到错误"Run-Time check failure #2 - stack around variable sub was corrupted"