Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you trap an Oracle "Unique Constraint" error in an event handle 1

Status
Not open for further replies.

emaduddeen

Programmer
Mar 22, 2007
184
US
Hi Everyone,

I created this error handler to trap when the user types in an dependent id from a data grid view using Oracle as the database. I did it to replace the default error dialog that is displayed when an error occurs:

Code:
    Public Sub DataErrorEventHandler(ByVal sender As System.Object, _
                                     ByVal e As System.EventArgs) _
        Handles DEPENDENTSDataGridView.DataError

        MessageBox.Show("My Actual Data Error Goes Here", "OOOPPPPS")
    End Sub

I don't know what code I need to add to the sub procedure to trap an Oracle "Unique Constraint" error. Could you tell me how to do it?

I wish to use a case structure to trap for this. Once I'm able to trap for this error then I plan to add more to the case structure.

Thanks.

Truly,
Emad
 
Your second parameter is wrong. It should be ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs.

Anyways, try this:

Code:
    Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DEPENDENTSDataGridView.DataError
        Dim ConstExcep As System.Data.ConstraintException
        ConstExcep = TryCast(e.Exception, System.Data.ConstraintException)

        If Not ConstExcep Is Nothing Then
            MessageBox.Show("This IS a constraint exception:  " & ConstExcep.Message) 'Constraint Exception
        Else
            MessageBox.Show("This is not a constraint exception:  " & e.Exception.Message)
        End If
    End Sub
 
Hi RiverGuy,

Thanks for the code. It works well.

Truly,
Emad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top