Check for duplicate in c# and sql

We have a currently c#/asp web app using a sql database, i'm trying to find a way to achieve the following...

When the user adds a new part to the database it checks to see if it exists before adding it, if it does find a duplicate it triggers a warning (ideally with some information on what part it has found as a conflict)

I'd like the warning to contain some basic details about the part that already exists if possible and for it to be triggered when the user clicks the save button.

Attached is the page in question (with code behind) from Control\Quotations\QuotationInfo
And an overview of the project to allow context
Who is Participating?
BuggyCoderConnect With a Mentor Commented:
in your procedure just write this:-

if exists(select id from yourtable where id='1234')
return -1;
your insertion here....

Return value can be read from procedure by adding the return parameter in sql parameters.
Here is an example:-
apply a unique constraint to check for duplicate data. trying to insert the duplicate data from ADO.NET would result in an exception which can be caught and alert can be shown to the user as given below:-
suityou69Author Commented:
Thanks for the links, after having a quick read im keen to explore the option of querying if the id already exists as opposed to catch the exception.

Any pointers would be appreciated

Thanks in advance
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.