How to prevent a repeat value found in the database

Posted 21 August 2011 - 10:51 PM

Hello
I want to enter a value in a text box to add it in the database, but this value may be found already in the database
This code adds data from text box to the database, but without solving the problem of repetition of the same value that already exist in the database

Replies To: How to prevent a repeat value found in the database

Re: How to prevent a repeat value found in the database

Posted 21 August 2011 - 11:09 PM

The below logic can work for you:
1. The database table column can be made primary key(if possible in your application)
2. If the entered value is repeated, SQL exception will be thrown that can be handled in the catch block where you can call the code of entering the value again.