派生的CRecordset问题 [英] Derived CRecordset Problem

查看:64
本文介绍了派生的CRecordset问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果对此的答案太简单,我先向您道歉.
我有一系列的SQL访问应用程序.我将所有Recordset都放入DLL中,以便各种应用程序可以利用相同的代码(很有意义).
连接字符串是在用户首次运行应用程序时动态创建的,并存储在注册表中.此功能和连接字符串的检索对于所有类都是通用的,因此我创建了一个CComRecordset类,该类通过重写Open()和GetDefaultConnect()来处理此问题,然后从该类派生我的所有记录集类. 问题是,当打开类时,未设置m_bAppendable和m_bUpdatable,并且Edit()调用会导致异常(当然).
我有很多记录集类,并且为提高效率而努力,我不想多次复制该defaultconnect代码,所以我忘了做什么才能使这项工作生效.
致谢,谢谢,
Garry

I apologize up front if the answer to this is too simple.
I have a series of SQL access applications. I placed all my Recordset''s into a DLL, so that the various applications can utilize the same code (makes sense).
The connection strings are created dynamically the first time the user runs the app, and stored in the registry. This functionality and the retrieval of the connection string is common to all classes, so I created a class CComRecordset that handles this by overriding the Open() and GetDefaultConnect(), and then derive all my recordset classes from that class.
The problem is, when the class is opened, m_bAppendable and m_bUpdatable are not set and an Edit() call causes an exception (of course).
I have quite a few recordset classes, and strive for effeciency, I don''t want to replicate that defaultconnect code multiple times, so what have I forgot to do to make this work.
Regards, and thanks,
Garry

推荐答案

找到了解决方案.
在基类中覆盖Open:
虚拟BOOL打开(UINT nOpenType =快照,LPCTSTR lpszSql = NULL,DWORD dwOptions =无);
但是,在构造函数中,通常使用以下内容定义数据集:
m_nDefaultType =动态集;
我将覆盖更改为:
虚拟BOOL打开(UINT nOpenType = AFX_DB_USE_DEFAULT_TYPE,LPCTSTR lpszSql = NULL,DWORD dwOptions = none);
现在,所有这些在我派生的CRecordset类中都可以正常工作...
Found the solution.
The override of Open in the base class:
virtual BOOL Open(UINT nOpenType = snapshot, LPCTSTR lpszSql = NULL, DWORD dwOptions = none);
However in the constructor, generally the dataset is defined with:
m_nDefaultType = dynaset;
I changed the override to:
virtual BOOL Open(UINT nOpenType = AFX_DB_USE_DEFAULT_TYPE, LPCTSTR lpszSql = NULL, DWORD dwOptions = none);
And now all works fine in my derived CRecordset class...


这篇关于派生的CRecordset问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆