• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

asp.net vb.net error messages from sqlserver

Need to know a  specific error returned by sqlserver. I need to know when sqlserver returns an error when try write a duplicate value in an indexed fileld.
0
rflorencio
Asked:
rflorencio
  • 2
  • 2
1 Solution
 
Christian de BellefeuilleProgrammerCommented:
don't you use a try/catch statement?

try
    ' your query
catch ex as exception
   ' Do whatever you want when an error occur...
   MyLabel.Text = ex.Message
end try
0
 
chuckdscCommented:
use the try_catch block to capture the sqlexception as follows


Try

Catch e As SqlException

End Try
0
 
rflorencioAuthor Commented:
In this case what i need is if the error occurs when try write a duplicate value in an indexed field. I need to know if this error specifically happened and not other.
0
 
Christian de BellefeuilleProgrammerCommented:
rflorencio, use your imagination! :-)

Try to insert a duplicate, set a break point in your catch statement, and watch for exception variable (in the case i mentionned, it's ex.ErrorCode).  Once you got the code, simply add an IF...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now