Custom Error Message When Database Not Updated

R

RoadKill

I have ASP forms to update my database. However if someone tried to submit a
duplicate entry, it just gives an ugly ASP error message that makes no sense
to an average user.

How can I create a custom error message when this happens. I am assuming an
If then statement can be applied to the Insert command but am not sure how to
pull that off.

Thanks!

strSQL = "INSERT INTO NewResults(Supervisor, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8,
Q9, Q10, User_name, PostedOn, ReviewType, Center) Values('" &
request.form("Supervisor") & "', '" & request.form("Q1") & "', '" &
request.form("Q2") & "', '" & request.form("Q3") & "', '" &
request.form("Q4") & "', '" & request.form("Q5") & "', '" &
request.form("Q6") & "', '" & request.form("Q7") & "', '" &
request.form("Q8") & "', '" & request.form("Q9") & "', '" &
request.form("Q10") & "', '" & request.form("User_name") & "', '" &
request.form("PostedOn") & "', '" &
request.form("ReviewType") & "', '" & request.form("Center") & "')"
 
J

Jon Spivey

Hi,
You can switch off the default asp error message like this

strSQL="..."
on error resume next
YourConnection.execute strSQL
if err.number <> 0 then
' put your own message here
' you could also write to a log email the webmaster etc
end if
on error goto 0 ' switch back to asp error handling


Cheers,
Jon
 
S

Stefan B Rusynko

While you can add a custom error message, you really don't want the database to ever generate an error from a duplicate record event
- by that time the error has occurred and the server side processing has ended

The correct ways to do it is to check for possible duplicate before you even attempt to insert the record
- usually by just running a query to check for a record with the key fields that you don't want duplicated (because they are set as
unique in the database)

Typically you would have a duplicate record check before the insert
<%
'query the DB for the record opening it with say objrs
'(using the form values of the key fields)
IF NOT objrs.EOF THEN ' check if record found
'The record was found so it would be a dupe if inserted
' close the dupe check record set
' Add your custom error message here and a link back to the form here
ELSE ' record not found so not a dupe
' close the dupe check record set
' include your insert record code here
END IF
%>




I have ASP forms to update my database. However if someone tried to submit a
duplicate entry, it just gives an ugly ASP error message that makes no sense
to an average user.

How can I create a custom error message when this happens. I am assuming an
If then statement can be applied to the Insert command but am not sure how to
pull that off.

Thanks!

strSQL = "INSERT INTO NewResults(Supervisor, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8,
Q9, Q10, User_name, PostedOn, ReviewType, Center) Values('" &
request.form("Supervisor") & "', '" & request.form("Q1") & "', '" &
request.form("Q2") & "', '" & request.form("Q3") & "', '" &
request.form("Q4") & "', '" & request.form("Q5") & "', '" &
request.form("Q6") & "', '" & request.form("Q7") & "', '" &
request.form("Q8") & "', '" & request.form("Q9") & "', '" &
request.form("Q10") & "', '" & request.form("User_name") & "', '" &
request.form("PostedOn") & "', '" &
request.form("ReviewType") & "', '" & request.form("Center") & "')"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top