I am having a problem entering new records into the database. There is a key field called 'Title' and sometimes I screw up and try to enter something that is already there. after entering the full data I save it but if there is a duplicate it shuts down with an error message. How can I capture this error and allow the user to abort the routine?
The entry code I believe is through BindingNavigator and below and the error below that. is my record save code. The error shows at the 'Me.DVD_ListBindingSource.EndEdit()' statement. If it makes a difference I am working in Visual Basic 2015.
Private Sub DVD_ListBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles DVD_ListBindingNavigatorSaveItem.Click
If MessageBox.Show("SAVE THIS RECORD TO THE DATABASE" &
vbCrLf & vbLf & "Are you sure?",
MessageBoxButtons.YesNo, MessageBoxIcon.Stop) =
Me.Validate() Me.DVD_ListBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me._D__DATA_FILES_DVD_LIST_MDFDataSet) MessageBox.Show("RECORD SAVED", "AS REQUESTED", Else MessageBox.Show("RECORD NOT SAVED", "AS REQUESTED", End If
The error msg.
An unhandled exception of type #39;System.Data.ConstraintException' occurred in System.Data.dll
What I have tried:
I originally thought of a Try-Catch method of catching the error and displaying it, but I'm not sure of what I'm looking for.