Wrox Programmer Forums
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 19th, 2006, 05:40 AM
Friend of Wrox
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default Checking for Duplicates


Does anyone have a solution to the problem of preventing duplicate records when adding records to a separate table?

I would like to display a grid view of products and allow the user to click a button on a row and add that product to a wish list table.
Before the record is inserted I would like to check that the item has not already been inserted.

If anyone has a solution or knows of a decent tutorial I would be very grateful.


Try our latest project www.nobanx.com Currency Exchange for members
Old July 19th, 2006, 11:05 AM
Authorized User
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts

Only way to do this is by code. You will have to query (with COUNT()) the table for the fields entered with the WHERE clause checking on each field to see if any rows match what the user inputted. If count is greater than "0" then you have a duplicate entry. Hard part about that is if they word it differently you will still get duplicates just worded differently.
Old July 20th, 2006, 08:41 AM
Friend of Wrox
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts

Thanks for your answer.

Another suggestion from someone was

Just do a;

SELECT ProductID FROM WishListTable WHERE ProductID = <selected Product ID>
If you don't get an empty result set back you know the product is already there. Or if you are using SQL Server Stored Procedures;

IF NOT EXISTS (SELECT 1 FROM WishListTable WHERE ProductID = <selected Product ID>)
    INSERT INTO WishListTable

These set me looking for tutorials and I found one at http://aspalliance.com/687

I've incorporated these suggestions and the tutorial into my system and it works a treat

Thanks again

Similar Threads
Thread Thread Starter Forum Replies Last Post
Yes to duplicates MMJiggy62 Beginning VB 6 3 July 14th, 2006 11:51 AM
Checking for duplicates toedipper2 SQL Server 2000 3 June 7th, 2006 03:50 PM
Duplicates in XSLT d_sathish XSLT 1 November 9th, 2005 11:45 AM
checking for duplicates jammykam Access 3 October 2nd, 2003 08:06 PM
Duplicates ashley_y Access 11 August 14th, 2003 03:41 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.