c++ - 我们如何使用 CRecordset 批量更新记录

标签 c++ database mfc odbc

我有一个 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/

相关文章:

ruby-on-rails - rails : Effects of changing the data type of an existing column with existing data

c++ - 如何强制 AfxMessageBox 以大型机为中心,而不是当前具有焦点的任何子窗口

c++ - MFC:如何设置CEdit框的焦点?

c++ - 如何使用 MFC 将记录插入到 Microsoft Access 中?

java - 从 JNI 到 Java 的字符 vector

c++ - (如何)我可以在 C++ 中使用字符串数组作为标识符?

c++ - 以逗号分隔的表达式调用析构函数

c# - “查询值的数量和目标字段不一样。”

mysql - rake 数据库 :schema:dump is not producing schema for all databases

c++ - C++ 中的 LRU 缓存