Jump to content
Xtreme .Net Talk

Recommended Posts

Guest Cheung
Posted
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
Guest Cheung
Posted

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.

  • *Gurus*
Posted

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

Guest Cheung
Posted

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. : )

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...