Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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 :((
Posted
Updated 12-Feb-11 8:23am
v2

Have you tried calling Close on m_pSet just before you call pMainView->UpdateView()?
 
Share this answer
 
Comments
Mr. Tomay 12-Feb-11 16:01pm    
Yes I did. But the problem remains :(
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();
 
Share this answer
 
v2
Comments
Mr. Tomay 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 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 :)
Mr. Tomay 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 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)... :)
Mr. Tomay 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900