Solved

Using CDaoRecordSet::Requery to refresh records

Posted on 2000-04-02
5
275 Views
Last Modified: 2013-11-20
Hi... I'm getting Recordsets by using a SQL statement in the CDaoRecordset::Open method.... my question is, if I need another SQL statement, is there a way to refresh the records without Closing the recordset and then Opening it again?

Thanks
Skel
0
Comment
Question by:skel
5 Comments
 
LVL 4

Expert Comment

by:inpras
ID: 2678832
     CDaoDatabase db;
      db.Open("c:\\Temp\\MyDB.mdb", FALSE, FALSE, _T(""));
      CDaoRecordset rs(&db);
      rs.Open(AFX_DAO_USE_DEFAULT_TYPE, "Select * from MyTab", 0);

      db.Execute("UPDATE MyTab SET MyName = 'ABCD'", 0);
      rs.Requery();
??
0
 

Author Comment

by:skel
ID: 2678843
No.... Execute doesn'r return any records.. I meant using SELECT statement

Skel
0
 
LVL 3

Expert Comment

by:_mb_
ID: 2679177
If the recordset is opened, you can't change the SELECT statement. The only way is to change the member variables m_strFilter and/or m_strSort to create new requery-conditions before you call the requery-method.
0
 

Expert Comment

by:z2000
ID: 2679236
If you need another SQL you must close and reopen because recordset is a set of record which you selected ->if not close (to empty buffer)old data and new data is conflicted ). In case use m_strFilter& m_strSort you have to use requery function but that function call Close and Open function (if you debug into Requery you'll see)
0
 
LVL 4

Accepted Solution

by:
inpras earned 50 total points
ID: 2679355
Wel even if execute will not reurn recordset for U I think since it updates table in UR database requery should work. see what I have done for small example

      CDaoDatabase db;
      db.Open("c:\\Temp\\MyDB.mdb", FALSE, FALSE, _T(""));
      CDaoRecordset rs(&db);
      rs.Open(AFX_DAO_USE_DEFAULT_TYPE, "Select * from MyTab", 0);

      db.Execute("UPDATE MyTab SET Name = 'ABCD'", 0);
      rs.Requery();
      rs.MoveLast();
      CString strNo;
      strNo.Format("%d", rs.GetRecordCount());
      AfxMessageBox(strNo);
      db.Execute("INSERT INTO MyTab VALUES('ABCD')", 0);
      rs.Requery();
      rs.MoveLast();
      strNo.Format("%d", rs.GetRecordCount());
      AfxMessageBox(strNo);

Hope this helps
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now