database - CRecordset::GetFieldValue() 抛出异常(但并非总是如此)
问题描述
有人可以解释这种奇怪的行为吗?
CString A, B;
CRecordset rs.Open( forwardOnly, "select A,B from table", readOnly);
// does not work:
rs.GetFieldValue( "A", A); // ok
rs.GetFieldValue( "B", B); // throws; m_nRetCode is set to -1;
//trace says "dbcore.cpp(174) : AppMsg - invalid descriptor index."
// works:
rs.GetFieldValue( (short) 0, A); // ok
rs.GetFieldValue( (short) 1, B); // ok
// does´nt work either !?
rs.GetFieldValue( rs.GetFieldIndexByName( "A"), A); // ok
rs.GetFieldValue( rs.GetFieldIndexByName( "B"), B); // asserts !?
// throws a different exception:
rs.GetFieldValue( "A", A); // ok
rs.GetFieldValue( "A", A); // throws, but m_nRetCode is 100 now and the trace is saying "data allready fetched" !?
// strange...
rs.GetFieldValue( (short) 0, A); // ok
rs.GetFieldValue( "B", B); // this works
rs.GetFieldValue( "A", A); // this asserts ???
我搜索了一个提示,说forwardOnly不是正确的光标,但使用快照不会改变任何事情。谁能解释一下?
有没有办法来解决这个问题?
解决方案
想我找到了答案:它似乎超出了SQLGetData()中的 CRecordset :
如果驱动程序不支持对 SQLGetData 的扩展,则该函数只能返回数字大于最后一个绑定列的未绑定列的数据。此外,在一行数据中,每次调用 SQLGetData 的 Col_or_Param_Num 参数的值必须大于或等于上一次调用的 Col_or_Param_Num 的值;也就是说,必须按列号递增的顺序检索数据。
https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetdata-function?view=sql-server-2017
推荐阅读
- python - python中的错误:“无法解压不可迭代的NoneType对象”
- python - 如何在轴'y'python数据框中绘制小时数
- compiler-construction - LLVM的内存依赖分析上下文中的“clobbers”是什么意思
- java - Java - 将 ArrayList 调用到另一个类
- asp.net-web-api - 无法从网络上的远程计算机访问 ASP.NET Core API
- javascript - 动画在打开购物车抽屉时工作一次,然后就不再工作
- php - 如何回显数据库中的项目
- java - 从文本文件写入时,数组只会将值设置为“0”
- c++ - 错误:从 'std::__1::basic_string 没有可行的转换
' 到 'const QString' - jupyter-notebook - 如何修复 JupyterLab 中 markdown 文件的文件加载错误