Click to See Complete Forum and Search --> : add a record


January 15th, 2000, 09:52 AM
i am developing a database program with Access. when i add a record to database,
the new record will be the last one of the database by default. i want to know how i can add a new record and make it be the first record.
thank you!
tom

rhermans
January 15th, 2000, 01:34 PM
I suppose you use a unique key in your db design, the location of your new record depends on the sorting in your database, is you open the database by using an SQL string that uses descending sorting your last entry becomes the first.
Something like
SELECT * FROM Table1 ORDER BY Table1.key DESC;
where Table1 is the name of your table and
table1.key is the field with your index
An autonumber field with new values prop as increment works perfect

January 19th, 2000, 10:19 AM
thank you for your reply.
i notice a document about the position of the new record in the msdn,
just as bellow:

.In a dynaset-type CdbRecordset object,
records are inserted at the
end of the CdbRecordset, regardless
of any sorting or ordering rules that were
in effect when the CdbRecordset was opened.
.In a table-type CdbRecordset object
whose CdbIndex property has been set,
records are returned in their proper
place in the sort order.
If you have not set the CdbIndex property,
new records are returned at the end of the CdbRecordset

so in my program i only can open my recordset with the table-type.
can i use the sql with "order by" clause to open the table-type recordset?
in my program, all the records are naturely order by the time that the records are generated. i only want to display the records in a descending order. the latest record is displayed first. i can use "order by [time] desc" to make it. but when there is a large amount of records in my database, opening the recordset will be very time-consuming. (it will take about 3-4 minutes to open a recordset with 200,000 records on a 500MHZ computer)
so i think if i can make my new record to be the first record of the table,
i can avoid using the time-consuming "order by".
do you have any good idea about it?
can you give me more detail codes(VB or VC)?

thanks again.
Tom

Lonely Wolf
January 19th, 2000, 05:28 PM
You can open your recordset, go to the last record (using movelast) and show every record from last to the first (moveprevious), so you don't need to order records.

bharat
January 20th, 2000, 12:30 AM
tom it is actually updated according to the primary key index i.e., let us assume u give a numeric field as the primary key and u r creating it automatically in the front end it will get updated according to the order i.e the no.1 will be the first record and no.2 will be the second record like this it goes on this matches even if u create a alphanumeric fields as primary key example (p000001,p000002). r u clear with this now if not please feel free to ask any more queries
thanks
bharat

January 20th, 2000, 08:53 AM
thank you,bharat
i have a new thought about the problem. create a query wirh decending order, and
open the query instead of the orginal table when i display the content of the table. i need not care about the position of the records in the database. how about it?
tom