CRecordset::m_strSort

Remarks

After you construct the recordset object, but before you call its Open member function, use this data member to store a CString containing an SQL ORDER BY clause. The recordset uses this string to sort the records it selects during the Open or Requery call. You can use this feature to sort a recordset on one or more columns. The ODBC SQL syntax for an ORDER BY clause is

ORDER BY sort-specification [, sort-specification]...

where a sort-specification is an integer or a column name. You can also specify ascending or descending order (the order is ascending by default) by appending “ASC” or “DESC” to the column list in the sort string. The selected records are sorted first by the first column listed, then by the second, and so on. For example, you might order a “Customers” recordset by last name, then first name. The number of columns you can list depends on the data source. For more information, see the ODBC SDK Programmer’s Reference.

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

For more information about SQL clauses, see the article SQL. For more information about sorting records, see the article Recordset: Sorting Records (ODBC). Both articles are in Visual C++ Programmer’s Guide.

Example

// Example for CRecordset::m_strSort

CCustSet rsCustSet( NULL );

// Set the sort string
rsCustSet.m_strSort = "District, Last_Name";

// Run the sorted query
rsCustSet.Open( CRecordset::snapshot, “Customers” );

CRecordset OverviewClass MembersHierarchy Chart

See Also   CRecordset::m_strFilter, CRecordset::Requery