Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone.

I have a textbox called PlateSerial were i insert unique serial numbers. This is not auto generated. Once the serial is inserted it is taken to the NumberPlate database.

What i want is that if i put a serial that has already been inserted in the database. It should not allow me to do so.

So how do i do this.

Please help. In addition if possible i would prefer code examples.

Thanks everyone
Posted
Updated 9-Dec-11 21:42pm
v2

1 solution

You can do this in two ways.

1) Build the logic to check for unique values yourself. In this case, everytime you insert a new row, first check if the serial number already exists. Loading them from the db before saving and then checking them would be the easiest though not the most efficient way. Other approaches could be to cache these values etc.

2) Allow the database to do this for you. Set a UNIQUE constrain on this serial no. column. This[^] should help you understand what a unique column is. This[^] should guide you futher and help you set up a constraint. Once this is setup, the database will not allow you to insert duplicate columns.

As a note, you should also look at primary keys - http://www.w3schools.com/sql/sql_primarykey.asp[^].
 
Share this answer
 
Comments
Kim Togo 10-Dec-11 3:47am    
+5 for the good answer.
Abhinav S 10-Dec-11 3:50am    
Thank you.
thatraja 10-Dec-11 3:55am    
5!
Abhinav S 10-Dec-11 3:58am    
Thank you thatraja.
Maazatron 10-Dec-11 4:15am    
It sort of worked... thanks...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900