Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 C++ MFC
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();
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
}
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.
}
 
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 Cry | :((
Posted 12-Feb-11 8:19am
tomay30001.2K
Edited 12-Feb-11 8:23am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have you tried calling Close on m_pSet just before you call pMainView->UpdateView()?
  Permalink  
Comments
tomay3000 at 12-Feb-11 16:01pm
   
Yes I did. But the problem remains :(
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Wouldn't it be possible
to share the view record set with the dialog ? Smile | :)
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();
  Permalink  
v2
Comments
tomay3000 at 13-Feb-11 15:45pm
   
Nice thinking, I'll try it.
Is the speed of ODBC driver for Updating recordsets considered as a bug in this king of situations?
Eugen Podsypalnikov at 14-Feb-11 1:58am
   
I do not know it yet, sorry.
Anyway I would try to exclude any "unneeded" rowsets concurrency...
The edited set by the dialog would be ready for the view directly, without any DB exchange :)
tomay3000 at 15-Feb-11 18:41pm
   
You said "The edited set by the dialog would be ready for the view directly, without any DB exchange :)". & that's what I found suitable for my app (I passed the edited set text strings as arguments in the UpdateView() function UpdateView(LPCTSTR lpszText1, LPCTSTR lpszText2, LPCTSTR lpszText3,
...)
).
I am using an .mdb database file: Should I switch to DAO instead of ODBC ?
Eugen Podsypalnikov at 16-Feb-11 1:38am
   
Yes, you could also pack your edited fields into a class, for example:
class CDataEntry
{
CString m_cszFieldA,
m_cszFieldB;
int m_iFieldC,
m_iFieldD;
..
};
 
...and then implement void CYourView::UpdateView(CDataEntry& cData); as well :)
 
The (any) DB-exchange (open/save/update/...) could be managed by the view only.
 
Sorry, I have not understood why you are saying about a DB-type switch (1),
 
and my DB-skills (speed/comfort/safety/...) are very poor (2)... :)
tomay3000 at 16-Feb-11 17:27pm
   
OK, thank you anyway ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 239
1 Sarvesh Kumar Gupta 185
2 George Jonsson 154
3 ArunRajendra 144
4 Richard MacCutchan 140


Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 13 Feb 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid