Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
when i insert a data into the database using insert query in asp.net, i get an exception like primart_key constraint violated... But i want to show the error as Data already exists in database with out that exeception...

In Vb6 we can do this with comparing the exception error number but there is no error number in .net how to do this.....
Posted
Comments
Prerak Patel 19-Sep-11 2:04am    
.Net has the exceptions.
Sergey Alexandrovich Kryukov 19-Sep-11 2:17am    
Why this seems to be a problem? And forget about stupid error numbers. The were rendered obsolete by Barbara Liskov in 1970s. Remember in what year do you live.
--SA

1 solution

Use try catch to catch SqlException.
VB
Try

Catch ex As SqlClient.SqlException
    ' check on ex.Number and display whatever you want

End Try
 
Share this answer
 
Comments
Pravin Patil, Mumbai 19-Sep-11 2:19am    
Good answer....
Prerak Patel 19-Sep-11 2:23am    
Thanks Pravin

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900