table without sorting

aerith_wc

New member
Local time
Yesterday, 17:05
Joined
Dec 31, 2007
Messages
1
Hi,

I'm using DAO in C++ to write data in MS Access table. I found that MS Access will automatically sort those records in ascending order based on the primary key. I need to leave those records based on the write sequence, can I do that?

Thank you in advance:)
 
Just an FYI, but an Access mdb file will NOT save records in any meaningful order, with the exception of a primary key field. The problem you have is that, if you do not have a primary key assigned, the records are still not necessarily saved in the order that they were written.

In order to get around this you should assign a date/time stamp for the entry and then use a query to access the data in the order you wanted.
 
A table is actually saved in a meaningful order, but to whom ;)

The Jet primary key designation, is a clustered index, meaning it (should) store records in primary key order. What happens, since Jet is a file based system, is that when adding records to a table, they are added where there's space. By some retrieval methods, that is perceived to be sequentially at the end of the table, but I think it could be "anywhere" within/at "the end of" the mdb file. When you do a compact & repair, the table is physically reordered in primary key order. If you don't have a primary key, it probably uses the first unique index, if no index, I don't know - perhaps the first column?

The retrieval method might - or might not (probably the latter) - return the records in that order. I think I've seen ADO and DAO return the same results in different order, and double clicking the table in the Access UI gave a different sort order (the "datasheet view" seen in the UI, is really a SELECT * FROM TheTable into a grid, where you can give a sort order for this DataSheet view by saving the "table design" after having done a sort).

Gist of it is, as Bob says, to be able to get information in a meaningful (to you) order, you have to provide means to return it in such order (a column with for instance a sequential number, date/time...), then use an ORDER BY clause on that column when you retrieve it.

Using =Now() as default value in a column for CreatedDateTime might be sufficient.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom