We help IT Professionals succeed at work.

SQL -error handling

amgavin
amgavin asked
on
Hi,
Does anyone know if there's a way to catch errors that occur in sql.
e.g.
UPDATE authors WHERE ID = 7.

Say ID number 7 doesn't exist. How do I catch this error?
Thanks

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012

Commented:
You can use the ADO Errors collection to catch these errors.  But perhaps you are referring to a Stored Procedure.

Anthony
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
If you use the Execute method of ADO, you have a RecordsAffected optional parameter that will return 0 under these circumstances.
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
We trap for some MS SQL errors in our project.  I'll try to find out which and how we are detecting them.  More in the morning.

mlmcc
Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
Please maintain:

Questions Asked 12
Last 10 Grades Given A A B B B B B A  
Question Grading Record 8 Answers Graded / 8 Answers Received

CERTIFIED EXPERT
Top Expert 2012

Commented:
amgavin,

You know assigning emoreau a grade of "C" without any explanation whatsoever, is really quite sad.  Have you actually read the EE Guidelines regarding points at http://devx.experts-exchange.com/jsp/cmtyQuestAnswer.jsp or were you just trying to make a point? Either way I am not impressed.

The irony is that due to an EE oversight, emoreau "record" shows an "A" and you a "C".  Guess who that is going to affect, next time you are asking a question here?

Anthony

Explore More ContentExplore courses, solutions, and other research materials related to this topic.