Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checking for duplicate keys when entering data in form
Message
De
11/08/1999 11:06:08
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00252239
Message ID:
00252542
Vues:
11
>I am still new to VFP programming.
>It appears that to add a record to a database via a form, you APPEND BLANK and then have the user enter the new data.
>I did not see any controls that would generate an error message if you tried to enter a duplicate key as happens with BTrieve and other databases.
>Under FoxPro 2.6 you can either go to EOF and SCATTER MEMVAR and not add the record if it is already present.
>Under VPF though, if the blank record is already created it would appear that you would have to do the following in the Validate control for the key field:
>
< code snipped >
> But this seems SO KLUDGY. Surely my understanding is incomplete.
>
>Thanks
>Bruce Strom


Apart from what others have told you (and what regards the primary key), you probably want to have some other key without duplicates. The simple solution is (for me) is to have this table open once more, under an appropriate order. My form class has something like this in its .init:
if not used(this.OtherAlias)
   select (this.DataEnvironment.InitialSelectedAlias)
   this.OtherAlias=alias()+"_2"
   use (dbf()) again in 0 order 1 alias (this.otherAlias)
endif
Later, in code, if I have to check if some key value already exists in the table, I simply check seek(this.value, thisform.OtherAlias). I may use the third parameter if it's not the first tag I use. The gotcha with your approach is that if you're using row buffering, as soon as you move off your new record (which a Seek would surely do), it's implicitly TableUpdate()ing, and your blank record is saved, like it or not. This way you use the other alias for surfing along your table, and don't move off your record in the main alias.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform