奇怪的CRecordset :: Update()行为 [英] Weird CRecordset::Update() behavior

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

问题描述

这次,我真的对CRecordset :: Update()的这种怪异行为深感困惑. 我有一个名为CMyRecordSet的基类CRecordset的类. &我正在使用一个SDI应用程序项目,该项目的主视图名为基类CView
CMyView 从主框架执行以下代码:

I am really stuck this time on this weird behavior of CRecordset::Update()
I have a class named CMyRecordSet of the base class CRecordset. & I am using an SDI app project that has a main view named CMyView of the base class CView
this code from the main frame is executed:

CMyEditDlg dlg; // CMyEditDlg is a CDialog base class, which uses CMyRecordSet to edit the database.
dlg.DoModal();


这段代码是CMyEditDlg::OnOK():
的实现


and this code is the implementation of the CMyEditDlg::OnOK():

CMyEditDlg::OnOK()
{
   m_pSet->Edit();
   if (m_pSet->UpdateData(TRUE))
      m_pSet->Update();
   // ...
   // Get a pointer of the main CMyView in pMainView
   // CView* pMainView = (CMyView*)((CFrameWnd*)AfxGetMainWnd)->GetActiveView(); for example
   pMainView->UpdateView(); // CMyView::UpdateView() will update the main view & draw the changes to that view.
}


这是它的代码:


this is its code:

CMyView::UpdateView()
{
   m_pSet = new CMyRecordSet();
   m_pSet->Open();
   // ...
   // Get the changes that was made by the CMyEditDlg::OnOK() from the database
}


问题是没有任何更改,只有旧的数据库数据得到了.
通过执行此操作,我发现问题是由于 ODBC 的速度引起的:


the problem is that there is no changes, only the old database data is got.
I found that the problem is due to the speed of ODBC by doing this:

CMyEditDlg::OnOK()
{
   m_pSet->Edit();
   if (m_pSet->UpdateData(TRUE))
      m_pSet->Update();
   // ...
   // Get a pointer of the main CMyView in pMainView
   // CView* pMainView = (CMyView*)((CFrameWnd*)AfxGetMainWnd)->GetActiveView();
   
   ::Sleep(1000); // <----------------- here will wait 1 second.
   
   pMainView->UpdateView(); // CMyView::UpdateView() will update the main view & draw the changes to that view.
}



除了::Sleep(1000);以外,还有什么其他方法可以加快ODBC服务器的速度或执行其他代码.因为::Sleep(1000);将冻结我的应用程序1秒钟.

请帮助我:((



Is there any other ways to speed up the ODBC server or do another code than ::Sleep(1000);. Because ::Sleep(1000); will freeze my app for 1 second.

Help me please :((

推荐答案

您是否曾尝试在调用pMainView->UpdateView()之前在m_pSet上调用Close ?
Have you tried calling Close on m_pSet just before you call pMainView->UpdateView()?


不可能吗
与对话框共享视图记录集? :)
Wouldn''t it be possible
to share the view record set with the dialog ? :)
class CYourView : public CView
{
  CYourRecordset m_cRecrdset;
..
public:
..
  CYourRecrdset* GetRecordset() { return &m_cRecordset; };
  void UpdateView() { .. };
..
};

class CYourDialog : public CDialog
{
  CYourView* m_pcView;
..
public:
  CYourDialog(CYourView* pcView)
  : CDialog(pcView, CYourDialog::IDD), m_pcView(pcView)
  {
    ASSERT(pcView);
  };
 ..
  virtual void OnOK()
  {
    if (m_pcView) {
      CYourRecordset* pcRecordset(m_pcView->GetRecordset());
      if (pcRecordset) {
        ..
        m_pcView->UpdateView();
      }
    }
    CDialog::OnOK();
  };
};

// now - just construct your dialog with the passing of your view pointer:
CYourView* pcView = ..;
CYourDialog cDlg(pcView);
cDlg.DoModal();


这篇关于奇怪的CRecordset :: Update()行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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