Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Coders,

Please help me get the last saved data from a table in a textbox so that i can compare it is unique. I know setting primary key will do this but in the user end i would like to show this. Like when when we enter a e-mail id for registering in a website it will show like "Email I.D Already Exists"

Hardly waiting for the reply.. Please help.
Posted

1 solution

You have a few different options on doing validation like this.
1) If using a stored procedure, you can let the procedure query the table before insert to validate that the new value is unique. If it is not, you can throw an exception back to the application indicating that the item already exists.
2) If you are using a direct query, then you will receive an exception back from the execution of the query if you have proper primary and unique constraints set up on your table.
3) This option is possible, but NOT the one I would choose as it requires extra calls to the database. You could also query the table in question from your application for a record matching the new entry before attempting to insert. If the record exists, you can deal with it the. If the record does not exist, then you insert it.
Cheers.
 
Share this answer
 

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