English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

hi..

I have a database with a primary key(Emp id).

I am having an insert form, display form, delete page form.

I want to validate the Employee id entered by the user in the insert form that means I want to check with the database, If it is already there in the database. I want to give an alert message when I try to submit the form.

'id 'is a primary key for that table.
How can I check the duplicate entry for Employee id while submitting the form?

thankx in andvance

2007-03-20 20:07:58 · 3 answers · asked by m 1 in Computers & Internet Programming & Design

3 answers

SELECT id FROM tbl WHERE id='user_entered_value'. If the query returns any data, then you have a duplicate. Otherwise, you're clear.

You could also do a try/catch and just insert the data, and if it fails, check the exception; if the exception is a primary key violation, then return feedback to the user.

2007-03-20 20:14:16 · answer #1 · answered by Rex M 6 · 0 1

Validation regulations shop rubbish values out of the database and are oftentimes carried out via verify constraints and so on. accepted key values are actually not strictly mandatory in each situation, yet maximum income from having a minimum of one unique key to perceive a given row.

2016-10-19 05:47:00 · answer #2 · answered by ? 4 · 0 0

yes insert will fail, you can provide the error message returned in the alert

2007-03-21 00:26:05 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers