|
-
May 6th, 1999, 03:45 AM
#1
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.
-
May 7th, 1999, 02:29 AM
#2
Re: Primary Key value appearing automatically for the new record in the Edit box
Change the data type to AutoNumber for that column.
-
May 10th, 1999, 01:56 AM
#3
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.
-
May 10th, 1999, 10:57 PM
#4
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?
-
May 11th, 1999, 05:02 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|