Guest Cheung Posted May 15, 2002 Posted May 15, 2002 my vb.net application inserts a record in the MS Access db. When I insert a record with duplicate primary key, an oledbexception is thrown. How can I know the reason of the exception? oledbexception.ErrorCode, OleDbError.SQLstate or which property I should refer to? and what is the value of the property? Thanks Quote
*Gurus* Derek Stone Posted May 15, 2002 *Gurus* Posted May 15, 2002 The whole point of a primary key is to be unique. You can't and shouldn't have two or more with the same value. Good Luck -CL Quote Posting Guidelines
Guest Cheung Posted May 15, 2002 Posted May 15, 2002 Thank for your prompt reply. Perhaps my question was unclear. Let me re-write my question as follow, When I insert a record into a table of MS Access , an OleDbException is thrown. How can I know the reason of the exception. I want to customize the warning messages instead of just print out the description message from the exception. Quote
*Gurus* Derek Stone Posted May 15, 2002 *Gurus* Posted May 15, 2002 Straight from the .NET SDK: Try myCommand.Connection.Open() Catch myException As OleDbException Dim i As Integer For i = 0 To myException.Errors.Count - 1 MessageBox.Show("Index #" + i.ToString() + ControlChars.Cr _ + "Message: " + myException.Errors(i).Message + ControlChars.Cr _ + "Native: " + myException.Errors(i).NativeError.ToString() + ControlChars.Cr _ + "Source: " + myException.Errors(i).Source + ControlChars.Cr _ + "SQL: " + myException.Errors(i).SQLState + ControlChars.Cr) Next i End Try Good Luck -CL Quote Posting Guidelines
Guest Cheung Posted May 16, 2002 Posted May 16, 2002 you are really nice. I was asking how I can know the meaning of the value of the properties of the Error object. For example, when I inserted a record with duplicate PK, the value of the Error.SQLstate is 3022. Is 3022 means "pk already exists in the database"? If yes, I can give out my own warning message instead of printing out Error.Message which may be too complicated for my users. : ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.