Searching in CRecordset

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.
Who is Participating?
MelissaCConnect With a Mentor Commented:
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)

Now your recordsetcursor points at the record you need.
look at CRecordset::GetDefaultSQL() or you can specify an SQL statement in the Open function.
forgot to mention Requery and the data members m_strFilter and m_strSort.
santamaAuthor Commented:
Thanks, all of the above work perfectly.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.