• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • 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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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