Solved

Using CDaoRecordSet::Requery to refresh records

Posted on 2000-04-02
5
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 51
sumNumber challenge 16 145
sum13 challenge 24 148
no14 challenge 14 76
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.

734 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