Solved

asp.net vb.net error messages from sqlserver

Posted on 2009-05-05
5
207 Views
Last Modified: 2012-05-06
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
Comment
Question by:rflorencio
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:cdebel
ID: 24308438
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
 
LVL 1

Expert Comment

by:chuckdsc
ID: 24311195
use the try_catch block to capture the sqlexception as follows


Try

Catch e As SqlException

End Try
0
 
LVL 1

Expert Comment

by:chuckdsc
ID: 24311197
0
 

Author Comment

by:rflorencio
ID: 24318804
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
 
LVL 10

Accepted Solution

by:
cdebel earned 500 total points
ID: 24319046
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question