vs2015 vc++ 使用CRecordset读取excel表格中的内容。
当单元格中字段较长时,使用GetFieldValue函数获取表单内容时报下面这样的错误:
d:\agent_work\1\s\src\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(4637) : AppMsg - Error: GetFieldValue operation failed on field 1.
Exception thrown at 0x766546d2 in LangPaser.exe: Microsoft C++ exception: CDBException at memory location 0x012fd5f0.
退出程序时有以下错误log显示:
Detected memory leaks!
Dumping objects ->
{1067} normal block at 0x02C3B170, 8 bytes long.
应该是内存泄漏的意思!但是我百度不到有用的解决方案!
包括Microsoft官网(https://learn.microsoft.com/zh-cn/previous-versions/visualstudio/visual-studio-2012/5f8k59f9(v=vs.110))的例子都是一样的结果,诡异的是它说了可能异常,但是没说解决办法,请问有没有知道的,请赐教!多谢!
关键代码如下:
CRecordset recset_translate_id(&xbase);
sSql2 = _T("SELECT * FROM [language0$] where text_id >= 0 ");
recset_translate_id.Open(CRecordset::forwardOnly, sSql2, CRecordset::readOnly);
CDBVariant varValue;
short nFields = recset_translate_id.GetODBCFieldCount();
while (!recset_translate_id.IsEOF())
{
for (short index = 0; index < nFields; index++)
{
recset_translate_id.GetFieldValue(index, varValue);
recset_translate_id.FreeDataCache();
// do something with varValue
}
recset_translate_id.MoveNext();
}
recset_translate_id.Close();
补充:诡异的是,当表格字段在前8行的时候即使字段很长也没问题!