Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
Dim Response As VariantType
Response = MessageBox.Show("Confirm Delete Record?", "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If (Response = vbYes) Then
StatusBar1.Panels(0).Text = "Deleting..."
If (Me.BindingContext(DataSet11, "DatabaseTable").Count > 0) Then
Me.BindingContext(DataSet11, "DatabaseTable").RemoveAt(Me.BindingContext(DataSet11, "DatabaseTable").Position)
Me.UpdateRemove()
End If
Else
Return
End If
End Sub
Public Sub UpdateRemove()
'Create a new dataset to hold the changes that have been made to the main dataset.
Dim objDataSetChanges As ProgramName.DataSet1 = New ProgramName.DataSet1() 'Stop any current edits.
Me.BindingContext(DataSet11, "DatabaseTable").EndCurrentEdit()
'Get the changes that have been made to the main dataset.
objDataSetChanges = CType(DataSet11.GetChanges, ProgramName.DataSet1)
'Check to see if any changes have been made.
If (Not (objDataSetChanges) Is Nothing) Then
Try
'There are changes that need to be made, so attempt to update the datasource by
'calling the update method and passing the dataset and any parameters.
Me.UpdateRemoveSource(objDataSetChanges)
DataSet11.Merge(objDataSetChanges)
DataSet11.AcceptChanges()
Catch eUpdate As System.Exception
'Add your error handling code here.
'Throw eUpdate
StatusBar1.Panels(0).Text = "Referential Constraint Enforced"
MessageBox.Show(eUpdate.Message)
'Me.sorting()
End Try
'Add your code to check the returned dataset for any errors that may have been
'pushed into the row object's error.
End If
End Sub
Public Sub UpdateRemoveSource(ByVal ChangedRows As ProgramName.DataSet1)
Try
'The data source only needs to be updated if there are changes pending.
If (Not (ChangedRows) Is Nothing) Then
'Open the connection.
Me.OleDbConnection1.Open()
'Attempt to update the data source.
Adapter1.Update(ChangedRows)
End If
Catch updateException As System.Exception
'Add your error handling code here.
Throw updateException
Finally
'Close the connection whether or not the exception was thrown.
Me.OleDbConnection1.Close()
End Try
StatusBar1.Panels(0).Text = "Record Deleted"
MsgBox(" Record Deleted ! ", MsgBoxStyle.Information)
cmdDelete.Visible = False
End Sub