C# - Avoiding Duplicate Data

Hi All,

I have a asp.net 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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Hope this helps!

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?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CraglyAuthor Commented:
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.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.