有人可以解释一下这种奇怪的行为吗?
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 范围:
If the driver does not support extensions to SQLGetData, the function can return data only for unbound columns with a number greater than that of the last bound column. Furthermore, within a row of data, the value of the Col_or_Param_Num argument in each call to SQLGetData must be greater than or equal to the value of Col_or_Param_Num in the previous call; that is, data must be retrieved in increasing column number order.
https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetdata-function?view=sql-server-2017
关于database - CRecordset::GetFieldValue() 抛出异常(但并非总是如此),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53059617/