在VC2010下使用数据记录集修改数据表出现系统崩溃问题的解决(m_pSet->AddNew()等函数)

VC6.0用m_pSet->AddNew()是好好的,在VS2012却出现系统崩溃,弹出来:

在调试窗口中提示:

Warning: Driver does not support requested concurrency.
Warning: Setting recordset read only.
Debug Assertion Failed!

Program: D:\MFCDemos\í?è′VS2012°?\StudSco1\.\Debug\StudSco.exe
File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp
Line: 64

其中关键的一行信息:“记录集为只读”。

造成这一问题的原因在于打开数据记录集的方式,在VC6.0中可以直接选择默认方式,即:

m_pSet->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL)

但在VS2010以上版本中(笔者使用的是VS2012,其他版本未测试),应该将默认方式改为动态记录集方式,即:

m_pSet->Open(CRecordset::dynaset,strSQL)

究其根源,在于CRecordset的Open函数的用法根据参数的不同有不同的结果,具体用法参看下文

CRecordset::Open
virtual BOOL Open( UINT nOpenType = AFX_DB_USE_DEFAULT_TYPE, LPCTSTR lpszSQL = NULL, DWORD dwOptions = none );
throw( CDBException, CMemoryException );

Return Value

Nonzero if the CRecordset object was successfully opened; otherwise 0 if CDatabase::Open (if called) returns 0.

Parameters

nOpenType

Accept the default value, AFX_DB_USE_DEFAULT_TYPE, or use one of the following values from the enum OpenType: 

CRecordset::dynaset   A recordset with bi-directional scrolling. The membership and ordering of the records are determined when the recordset is opened, but changes made by other users to the data values are visible following a fetch operation. Dynasets are also known as keyset-driven recordsets.


CRecordset::snapshot   A static recordset with bi-directional scrolling. The membership and ordering of the records are determined when the recordset is opened; the data values are determined when the records are fetched. Changes made by other users are not visible until the recordset is closed and then reopened.


CRecordset::dynamic   A recordset with bi-directional scrolling. Changes made by other users to the membership, ordering, and data values are visible following a fetch operation. Note that many ODBC drivers do not support this type of recordset.


CRecordset::forwardOnly   A read-only recordset with only forward scrolling.
For CRecordset, the default value is CRecordset::snapshot. The default-value mechanism allows the Visual C++ wizards to interact with both ODBC CRecordset and DAO CDaoRecordset, which have different defaults.

For more information about these recordset types, see the articleRecordset (ODBC) in Visual C++ Programmer’s Guide. For related information, see the article ”Using Block and Scrollable Cursors" in the ODBC SDK Programmer's Reference.

Caution   If the requested type is not supported, the framework throws an exception.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值