Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Primary key
Message
De
18/10/2007 18:38:45
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01261997
Message ID:
01262028
Vues:
21
>I am almost there
>
>I created the primary key
>
>Now when try to uptadate the table
>and the item already exists, the message appears:
>
>"the uniqueness is been violated"
>
>How can I prevent this message, or simply
>prevent the record from being updated ?

The idea of a primary or candidate key is precisely to avoid duplicates.

If you already have duplicates in the table, you must clean them up BEFORE creating the index.

Afterwards, there are several things you can do.

For example, when you try to save the data with TableUpdate() - I am assuming that you use buffering - if TableUpdate() returns .F., check for the error, with the function aerror(). If it is a duplicate, tell the user this, so the user has to change the data and try to save again.

Of course, TableUpdate() may fail for a variety of reasons, for example, the table is read-only, or some other rule is violated.

A simple validation is somewhat like this:
if not TableUpdate()
  local laError
  aerror(laError)
  * Show error message
  MessageBox("Error saving data, error #" + trans(laError(1);
    + " - " + laError(2))
endif
Of course, you can check the individual error numbers, and give more specific error messages in some cases.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform