This is a constraint that is best handled in the database itself, not in the code. If you have control over the structure of the database, create a unique index on the field. In access, I believe it's a combo box called "Indexed" - select Yes, No duplicates. In SQL, it'll look like "CREATE UNIQUE INDEX name ON table (column)". Either way, the db will prevent duplicate records.
If (and only if) you have no control over the structure of the database, it's a 2-step procedure. Query the table for records that match (select * where field='no duplicates'). If you get no results, then insert the record. And be wary of race conditions if the db is multiuser!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.