Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort ADOTable on integer value

Status
Not open for further replies.

MLNorton

Programmer
Nov 15, 2009
134
US
I have an ADOTable of over 3,000 records. I need to sort on an integer field, ID. ID is created on entry of a new record starting at 1 and incremented on each new entry. The ID field is a Number field.
ADOTable1.sort := ID fails.
How do I solve my problem?
 
Database tables are not sorted. There are no relationships between records in any database table.

What you need to do is use a query (TADOQuery), and use SQL to request particular (or all) fields from some (or all) records from your database. You can also specify what order they are presented.

eg.

Code:
SELECT * FROM MyTable ORDER BY Field1

is SQL that will retrieve all fields from your database table and sort on Field1. Change MyTable and Field1 as required. It's also good practice to only select the fields required for any particular task. eg.

Code:
SELECT Field1, Field2, Field5a FROM MyTable

While we can help you with SQL, this forum is not really the correct one to ask questions about it. Try one of the other SQL forums on tek-tips, or other resources out there on the web.
 
You can create an index on the fields you want to sort on and set the ADO.indexname to the name of that index. Indexname is listed in the object inspector, so if there's an index already defined, it should show up (indexname will have all the defined indexes available in its dropdown)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top