CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: add a record

  1. #1
    Guest

    add a record

    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



  2. #2
    Join Date
    Jan 2000
    Location
    Belgium / Europe
    Posts
    8

    Re: add a record

    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



  3. #3
    Guest

    Re: add a record

    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


  4. #4
    Join Date
    Nov 1999
    Location
    Italy
    Posts
    80

    Re: add a record

    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.

    Something over there is coding....
    ... and you don't know!

  5. #5
    Join Date
    May 1999
    Location
    India
    Posts
    9

    Re: add a record

    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


  6. #6
    Guest

    Re: add a record

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured