Hello Guys,

I have database one of the fields is set as primary key? When somebody try‘s to add duplicate value of cause gets an error. Is there a way to capture database duplicate key error so I can display message box when this particular error occurs.

Code:
Public Sub Modify(ByVal SqlStr As String, ByVal OleDbConnection1 As OleDbConnection)
        Dim oledbMommand As OleDbCommand
        oledbMommand = New OleDbCommand(SqlStr, OleDbConnection1)

        Try
            OleDbConnection1.Open()
            oledbMommand.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            OleDbConnection1.Close()
        End Try

    End Sub
Thank you.