我想确保我的RAII类总是在堆栈上分配.
如何通过"新"运算符阻止类分配?
我正在研究几个使用 ADO 访问 SQL Server 数据库的 Visual Studio 2015 C++ 项目类型。简单示例对表执行选择、读入行、更新每一行并更新表。
MFC 版本工作正常。Windows 控制台版本是我在更新记录集中的行时遇到问题的地方。update()记录集的方法抛出一个 COM 异常,错误文本为:
L"Item cannot be found in the collection corresponding to the requested name or ordinal."
Run Code Online (Sandbox Code Playgroud)
用HRESULT的0x800a0cc1。
在这两种情况下,我都使用定义为的标准 ADO 记录集对象;
_RecordsetPtr m_pRecordSet; // recordset object
Run Code Online (Sandbox Code Playgroud)
在MFC版本中,更新记录集中当前行的函数是:
HRESULT CDBrecordset::UpdateRow(const COleVariant vPutFields, COleVariant vValues)
{
m_hr = 0;
if (IsOpened()) {
try {
m_hr = m_pRecordSet->Update(vPutFields, vValues);
}
catch (_com_error &e) {
_bstr_t bstrSource(e.Description());
TCHAR *description;
description = bstrSource;
TRACE2(" _com_error CDBrecordset::UpdateRow …Run Code Online (Sandbox Code Playgroud)