Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to prevent same user-id insertion during a new user creation in asp.net?how will I do the checking from sqlserver?
Posted
Comments
StianSandberg 24-Jul-12 7:34am    
I think you should be a little more precise here. What is "user-id" in your code? Is it a username or an increasing number?

Make the ID column of your table Primary Key[^]

SQL PRIMARY KEY Constraint[^]
-The PRIMARY KEY constraint uniquely identifies each record in a database table.
-Primary keys must contain unique values.
-A primary key column cannot contain NULL values.
-Each table should have a primary key, and each table can have only ONE primary key.
 
Share this answer
 
Comments
StianSandberg 24-Jul-12 7:31am    
5+The correct answer! Use PK
Prasad_Kulkarni 24-Jul-12 7:42am    
Thank you Alluvial!
You need to check it via a query like:
SQL
SELECT COUNT(*) FROM MyTable WHERE UserName  = @CheckUserName

If the count returned from the database is greater than zero then it means that the username is already taken.

Call DB using the query and implement the flow based on the result retrieved. Try!
 
Share this answer
 
Comments
_Amy 24-Jul-12 8:00am    
Nice Advice. My +5!
Sandeep Mewara 24-Jul-12 8:15am    
Thanks.

Based on the vote counts and the 1-votes I got here, it looks like others didnt like my answer much! :)
I am sure they misunderstood the question and everyone had different perspective of the question asked.
_Amy 24-Jul-12 8:25am    
Your answer is very clear to me. It's a good idea with no performance issues. We are using this already. :) All the best.
Mohamed Mitwalli 24-Jul-12 10:36am    
+5
There is several way you can do this.

- use unique constraints with column Name of your table. it prevents to insert duplicate user-id.

- On submit, you can check whether this user-id is already exist or not in your db table.

- you can provide a button to check uniqueness about user id before submit.
 
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