CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Primary Key value appearing automatically for the new record in the Edit box

    I have made a program in VC++5.0 and it is hooked up with access database. The database contains a field of type long integer as the primary key. I want its value should appear automatically when I try to add a new record.


  2. #2
    Join Date
    May 1999
    Posts
    42

    Re: Primary Key value appearing automatically for the new record in the Edit box

    Change the data type to AutoNumber for that column.


  3. #3
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Re: Primary Key value appearing automatically for the new record in the Edit box

    Sir I tried but it didnt work. I want that when I go to Add record option then it must automatically display the new value for that field in the text box. Right now when I put data I get this message box " Can't update 'BooksIssueID'; field not updatable." When I leave this field empty I get following message "
    Please enter an integer" . This field has been declared as primary key in the access database and I am using CRecordSet class.



  4. #4
    Join Date
    May 1999
    Posts
    42

    Re: Primary Key value appearing automatically for the new record in the Edit box

    If this is a multi-user database, you really can't know the value to put into the edit box until you attempt to add the record because another user may add a record in the time it takes for you to fill in the form and add your record. For example, suppose you bring up the form to add a new record and at that time, the next number to be assigned is 25. During the time it takes you to fill in your form, another user commits a new record to the database, which causes that record to be assigned number 25 and yours will become 26 (or greater if other users also add records before you).

    You can only be assured of the number if you prevent other users from adding while you're adding, which defeats one of the purposes of having a multi-user database.

    What's the reason for needing to show the primary key value in the edit box? If the user can change it, the add operation may fail because a value already in the database may have been entered. Can you just display nothing until the record has been committed, then retrieve the value assigned to the record and show that to the user?



  5. #5
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Re: Primary Key value appearing automatically for the new record in the Edit box

    Sir you have given me a good advice. I think I am doing the same. I have a books issue/return form and I am asking the book Accession No and Mem ID. The rest of the things like issue date, return date, Fine are calculated automatically. Ofcourse the BookIssueID which is the primary key also gets incremented and I can see its new value in the record display form. I am for the first integrating Visual C++ program with a database so I was checking different options.
    Zulfi.


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