共用方式為


CRecordset::m_strFilter

After you construct the recordset object, but before you call its Open member function, use this data member to store a CString containing a SQL WHERE clause.

Remarks

The recordset uses this string to constrain (or filter) the records it selects during the Open or Requery call. This is useful for selecting a subset of records, such as "all salespersons based in California" ("state = CA"). The ODBC SQL syntax for a WHERE clause is

WHERE search-condition

Note that you do not include the WHERE keyword in your string. The framework supplies it.

You can also parameterize your filter string by placing '?' placeholders in it, declaring a parameter data member in your class for each placeholder, and passing parameters to the recordset at run time. This lets you construct the filter at run time. For more information, see the article Recordset: Parameterizing a Recordset (ODBC).

For more information about SQL WHERE clauses, see the article SQL. For more information about selecting and filtering records, see the article Recordset: Filtering Records (ODBC).

Example

CCustomer rsCustSet(&m_dbCust);

// Set the filter
rsCustSet.m_strFilter = _T("L_Name = 'Flanders'");

// Run the filtered query
rsCustSet.Open(CRecordset::snapshot, _T("Customer"));

Requirements

Header: afxdb.h

See Also

Reference

CRecordset Class

Hierarchy Chart

CRecordset::m_strSort

CRecordset::Requery