Inserted records are automatically sorted in MS Access database C#.NET
When insert data using OLEDB Jet provider, the data are inserted properly, but the order in which I have inserted is not kept as is. Instead it'开发者_运维百科s automatically changing the order.
How to make the inserted records in the same order ??
You shouldn't be worrying about the order data is stored in a table. Order is a presentation layer issue and when you want a particular order, specify a sort order (ORDER BY in SQL).
If you're using table datasheets in your application and expecting a desired sort order, then you should be using a form with a sort order defined (either in the form properties or in the underlying recordsource) or a query datasheet in place of the table datasheet.
Access also allows you to set a sort order in a table datasheet and save it with the table, but this is not advisable. Table datasheets are convenient, but you should not depend on them for anything but a quick-and-dirty view of the data.
I think that have to do with Primary Key. Let's say your PK is text based, then MS Access will sort it alphabetically. If you want to have control of the Order use an AutoNumber as PK.
Within a database, if you need records to be returned in a certain order you need to specify an 'ORDER BY' clause in your read code:
SELECT Field1, Field2 FROM Table ORDER BY Field1
Anything else has no guarantee of working going forwards.
精彩评论