Link to home
Start Free TrialLog in
Avatar of dino_p
dino_p

asked on

Error because of Primary Key Value Duplicate

I am using a stored procedure (it does not return a Recordset, all it does is add the 2 variables) to add 2 variables (a name, a zip).  A name cannot contain the same zip.  If you try to add it, the ODBC driver gives an error back saying no duplicate values to the primary key.  I want to capture this error (I tried using the Errors collection, no luck) and then notify the user of the mistake.  PLease help.

i'm using sql and doing asp pages.

i've tried your solution, i even tried it yesterday by my own discovery, but keep getting syntax error between goto and InsertError
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dino_p
dino_p

ASKER

i'm using sql and doing asp pages.

i've tried your solution, i even tried it yesterday by my own discovery, but keep getting syntax error between goto and InsertError
Why not trap the error in your Stored Proc and raise a custom error to ASP.
--- SQL ---
INSERT INTO junk_table (Name, Zip) VALUES (@Name,@Zip)
IF @@ERROR <> 0
    BEGIN
        RAISEERROR('This is the error I want to trap', 16, 1)
    END
-----------
You can specify a custom error number also.  So trap for that in your ASP code.

Hope this helps.
No comment has been added lately.
To cleanup this TA, I will recommend to moderators that this question is:
 
*** Answered by: Dhaest ***
 
Please leave any comments here within the next seven days, or finalize the question if you own it
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
peterchen
EE Cleanup Volunteer

per recommendation

SpideyMod
Community Support Moderator @Experts Exchange