?
Solved

Using CDaoRecordSet::Requery to refresh records

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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