Solved

Searching in CRecordset

Posted on 1998-10-02
4
184 Views
Last Modified: 2013-11-20
I have a program that uses an Access database through ODBC. In order to search for a particular record I go record by record checking the search criteria. Is there an easy way of doing this, such as a WHERE clause.
0
Comment
Question by:santama
  • 2
4 Comments
 

Expert Comment

by:mmachie
ID: 1322862
look at CRecordset::GetDefaultSQL() or you can specify an SQL statement in the Open function.
0
 

Expert Comment

by:mmachie
ID: 1322863
forgot to mention Requery and the data members m_strFilter and m_strSort.
0
 
LVL 2

Accepted Solution

by:
MelissaC earned 100 total points
ID: 1322864
When you've derived your own CRecordset class, you've allready got the member variables that are needed for your full query (the entire table). Instead of just saying CMyset.Open(), you can create an SQL-string:

CString sql="Select * from mytable where ID=123";
//then open your recordset with:

CMyset newset();  //create recordset
newset.Open(recordset::dynaset, sql);

//move to first record (if recordset!=empty)
newset.MoveFirst();

Now your recordsetcursor points at the record you need.
0
 

Author Comment

by:santama
ID: 1322865
Thanks, all of the above work perfectly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
Unix / Linux grid computing 5 149
Define unique primary key 9 89
FizzBuzz challenge 9 77
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

21 Experts available now in Live!

Get 1:1 Help Now