我有一个 mfc 应用程序,它使用 CRecordsets 来获取和更新/插入数据。
我能够实现批量行获取,但我现在希望使用派生的 CRecordset 实现批量行更新/插入/删除。
有人做过吗?能否提供代码示例?
最佳答案
我偶然发现了一篇描述如何在 CRecordset 上实现批量行更新的旧帖子。 首先,您必须实现 bulk row fetching在您的记录集上(您还可以查看 this post 作为示例)
一旦您使用记录集来获取数据,这就非常简单了。
//Declare your recordset
CMyRecordsetBulk regSetBulk(&myDatabase);
//Open it
regSetBulk.Open(NULL, NULL, CRecordset::useMultiRowFetch);
//Select the row you want to change
regSetBulk.SetRowsetCursorPosition(nRow);
//Update the value(s) you need to change.
regSetBulk.m_pnPrecision = 21;
//Set the length of the data in the field you modified (the "Precision" field is a byte)
regSetBulk.m_plnPrecision = 1;
//Do the same thing for a couple of other rows
regSetBulk.SetRowsetCursorPosition(++nRow);
regSetBulk.m_pnPrecision = 32;
regSetBulk.m_plnPrecision = 1;
regSetBulk.SetRowsetCursorPosition(++nRow);
regSetBulk.m_pnPrecision = 21;
regSetBulk.m_plnPrecision = 1;
regSetBulk.SetRowsetCursorPosition(++nRow);
regSetBulk.m_pnPrecision = 12;
regSetBulk.m_plnPrecision = 1;
//Update the rows and check for errors
int nRetCode;
AFX_ODBC_CALL(::SQLSetPos(regSetBulk.m_hstmt, NULL, SQL_UPDATE, SQL_LOCK_NO_CHANGE));
regSetBulk.CheckRowsetError(nRetCode);
关于c++ - 我们如何使用 CRecordset 批量更新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9116842/