Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i need a validation to restrict the entries of duplicate data in my database. i am using asp.net, c# and sql server as my development environment.
i have in total four tables in a database called 'CGRT' and table names being project,staff,yearly,monthly . please give me a solution so that i can restrict the entries of duplicate data i would prefer if its at client end with a error msg.
Posted
Comments
Kuthuparakkal 28-Oct-12 7:52am    
Have you tried implementing Primary Keys ?

I'm not coding it for you!

The way I would have done it, if resource use was not an issue, and it was 100 or less rows in the tables, was to load the relevant table(s) into a DataSet[^] and search through all rows in the first column (not the record ID column if it has one), if the first fits compare each relavant field on the row using String.Compare() and should all match, then return error message or whatever you want.

Now I use C# for desktop so I don't need to worry to much about resources, but if this is on a website calling another websites SQL server, it's not a good fix.

hope this was helpful!

-frank

PS: feel free to comment on this if I'm missing the point of the question entirely
 
Share this answer
 
The better and most optimized solution is to write a query or stored procedure which returns the count of the existing values if count is not equal to zero means you already have this record in your table skip further insertion.

The term 'Duplicate Entries' only be defined you so you have to modify the query with your parameter a sample query look like this.

eg: select count(staffName) from student where staffName ='Bingo'
this query will return number of items that matches staffName Bingo. If Bingo already exists it will return 0. else the number of occurrence
 
Share this answer
 
hi,

You can use EXISTS for your solution.
SQL
SELECT DepartmentID, Name 
FROM HumanResources.Department 
WHERE EXISTS (SELECT NULL)
ORDER BY Name ASC ;


Refer this link for better result.Preventdiuplicate record entry

Thanks
 
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