• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

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.
0
santama
Asked:
santama
  • 2
1 Solution
 
mmachieCommented:
look at CRecordset::GetDefaultSQL() or you can specify an SQL statement in the Open function.
0
 
mmachieCommented:
forgot to mention Requery and the data members m_strFilter and m_strSort.
0
 
MelissaCCommented:
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
 
santamaAuthor Commented:
Thanks, all of the above work perfectly.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now