Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Finding duplicate keys
Message
 
 
À
14/01/1999 12:16:18
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00176022
Message ID:
00176038
Vues:
28
>>>>>>When the user enters a new unit, or modifies the current one, I need to save it. But I don't want it to save if the unit is a duplicate. I also want to be the one to give the error message.
>>>>>>
>>>>>>Currently, I have a complicated IF to determine if the unit has changed and then I scan through the table to see if it's already there. I also have to make sure I don't get an error if the user changes the unit name, then changes it back, because then it will have changed AND be in the table already.
>>>>>>
>>>>>>It seems like there should be a simpler way of doing this. I've made the unit name a candidate index. Can I do the row update and have it tell me if the key's uniqueness was violated?
>>>>>>
>>>>>>Is there some way to put this in the database so whenever a user tries to save a duplicate unit, my error message comes up an the save is rejected?
>>>>>>
>>>>>>Thanks,
>>>>>>
>>>>>>-Michelle
>>>>>
>>>>>I think Candidate Tag is normal solution here.
>>>>
>>>>Candidate Tag? Is that different than making a field a candidate key? If not, and since it's already a candidate key, I don't see how that's a solution...
>>>>
>>>No, it's the same :). What's wrong you found? When you try to save a record, VFP will raise uniqueness violation error and you may trap it nicely.
>>
>>I guess I'm not clear on error trapping. Do I do something like this:
>>
>>ON ERROR llNotSaved = .T.
>>TABLEUPDATE()
>>IF llNotSaved
>>*Error message
>>ON ERROR
>>
>Yes, it's simplified example and should work Ok. I would just change lines:
>cError=on("error")
>ON ERROR llNotSaved = .T.
>TABLEUPDATE()
>ON ERROR &cError.
>IF llNotSaved
>*Error message

Ok, thanks.

-Michelle
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform