catching sql exception type
-
I have a problem. Whenever we pass an insert statement against database table the exception can be cathced by using sqlexception parameter. I have done with exception where there is a problem with the primary key because i know the error code it genereates when there is a primary key error. But how can i do the same type of checking when there is an error related to foreign key. Wht is the error code for foreign key related errors. Something like below
try { insert into database; if (success) then do nothing; else check about the cause of exception } catch { if (primary key exception) dosomething; else if(foreign key exception) dosomething; else dosomething; }
any help will be wellcomed. Any suggestion is well received. thanx in advance -
I have a problem. Whenever we pass an insert statement against database table the exception can be cathced by using sqlexception parameter. I have done with exception where there is a problem with the primary key because i know the error code it genereates when there is a primary key error. But how can i do the same type of checking when there is an error related to foreign key. Wht is the error code for foreign key related errors. Something like below
try { insert into database; if (success) then do nothing; else check about the cause of exception } catch { if (primary key exception) dosomething; else if(foreign key exception) dosomething; else dosomething; }
any help will be wellcomed. Any suggestion is well received. thanx in advanceIf I have a problem like this I create a simple test application and experiment. I would create an INSERT that will cause a foreign key violation and see what it returns. How did you find the value of the Primary Key error in the first place?
Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog