Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 28-Oct-12 2:50am
Comments
Kuthuparakkal at 28-Oct-12 7:52am
   
Have you tried implementing Primary Keys ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

hi,
 
You can use EXISTS for your solution.
SELECT DepartmentID, Name 
FROM HumanResources.Department 
WHERE EXISTS (SELECT NULL)
ORDER BY Name ASC ;
 
Refer this link for better result.Preventdiuplicate record entry
 
Thanks
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 400
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100