C# - Avoiding Duplicate Data

Posted on 2006-03-23
Last Modified: 2012-08-13
Hi All,

I have a 1.1/sql server 2000 web based administration system where I create and update records. What I want to do is to check that no record with the same name exists in the database before I create or update a record. I have managed to accomplish this with the create as I used a stored procedure to check if a record exists with the same name and return an output parameter depending on the result.

The problem I am having is that when I do an update on a record that has 3 fields I do a check on the name field and see if it exists before I allow the update just incase the user has changed the name to something that already exists in the system. However if the user has changed fields 2 or 3 but does not change the name then the update fails as it says the record already exists in the database.

There are three fields:


The stored procedure checks on update to see if the username already exists before it does the update. But if the administrator only changes the password the update will not work as the Username already exists in the database.

Can anybody help me out with this one??

Many thanks

Question by:Cragly
    LVL 9

    Expert Comment

    Hi Cragly,
    can you post the stored procedures code? and the update code?

    Hope this helps!

    LVL 15

    Accepted Solution

    In the stored procedure just check your 3 params against the three in the database. If anything has changed then update.

    But if you are already at the database then just run the update anyway... It's not like it's going to compromise your data in any way?

    Author Comment

    Many thanks,

    What I will do is check the username in the database with the updated username. If it has changed then I will check to see if there is an identical record with that username before I dop the update. If the username is the same then I can just do the update anyway as sugested.



    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now