Click to See Complete Forum and Search --> : CRecordSet -->Sort
Morftje
July 6th, 1999, 02:07 PM
Hi all,
How do I get the data out of my Access-Database into my flexgrid, sorted on one of the recordfields, chosen by me?
I can get the data into my flexgrid, but only sorted on the ID-number.
m_...Set.SetCurrentIndex(recordfieldvariable)
gives no error, but a Debug Assertion Failure.
Thanx.
Student Flanders Language Valley
Programmer
PeterK
July 6th, 1999, 02:15 PM
From the on-line help for DAO:
Records returned from a table-type recordset can be ordered only by the indexes defined for the underlying tabledef. To sort records in some other order, you can open a dynaset-type or snapshot-type recordset using an SQL ORDER BY clause stored in CDaoRecordset::m_strSort.
Morftje
July 7th, 1999, 02:32 AM
Where can I get more info concerning this subject?
Student Flanders Language Valley
Programmer
PeterK
July 9th, 1999, 11:24 AM
You are not really using CRecordSet are you? SetCurrentIndex is a method of CDaoRecordSet.
Anyway, all you need to do is set up your m_strSort variable before you do an Open() or Requery() for your recordset any the sort should take place. On-line help exists for CDaoRecordSet::m_strSort.
Here is an example:
pConditionsSet->m_strSort = "[ConditionSetID], [Logic]DESC, [FieldID]";
This sorts my recordset in ascending ConditionSetID, descending Logic and ascending FieldID.
After setting the m_strSort variable make your call to Open() or Requery().
Hope this helps.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.