Click here to Skip to main content
16,010,503 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
how to we prevent duplicate value on database table through c# code when inserting details
Posted

Simple: check first to see if they are already in the database, and if they are, don't insert them...

Without your data and table definitions, we can say no more.
 
Share this answer
 
Comments
CPallini 10-Dec-13 9:28am    
5.
0)Use Constraints[^](PrimaryKey, Unique)

1)Before insert the record, check existence of the value in that table, sample query like below, if count is above 0 then value exists & you should notify the user about duplicate value(OR generate different ID....it's based on your requirement)
SQL
SELECT COUNT(*) FROM Table_Name WHERE Column_Name='SomeValue'
 
Share this answer
 
Comments
Ashish_Agrawal 10-Dec-13 9:23am    
OP asked through C# code. :)
thatraja 10-Dec-13 9:29am    
Don't underestimate our OP, he knows how to write code based on suggestions.

:)

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