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)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.