[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using CDaoRecordSet::Requery to refresh records

Posted on 2000-04-02
5
Medium Priority
?
376 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 150 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 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