Private Sub DeleteBtn_Click(sender as object, e as EventArgs) handles DeleteBtn.Click
If myBindingSource.Current IsNot nothing then
DirectCast(myBindingSource.Current, DataRowView).Row.Delete()
'The Above method basically sets the DataRow.RowState to
' DataRowState.Deleted
myBindingSource.EndEdit()
' Either
CommitDeletedRows(myDataTable, myTableAdapter)
' or if you want to be dynamic about it
' Though it should be noted for such a dynamic method you will
' still need to find the appropraite Typed TableAdapter for such a
' DataTable, or learn to write a SqlCommand Delete statement on the
' Fly
'if Typeof myBindingSource.DataSource is DataSet then
' CommitDeletedRows(DirectCast(myBindingSource.DataSource, _
' DataSet)(myBindingSource.DataMember))
'elseif TypeOf myBindingSource is DataTable then
' CommitDeletedRows(DirectCast(myBindingSource.DataSource, _
' DataTable))
'End If
End If
End Sub
'Now there are multiple ways to handle the Deletion of flagged DataTable
'DataRows, in order to commit them to the MDB file.
'And this Of course is easier if you either know the direct DataSet or
'DataTable involved with the deletion.
'As well, this is also affected if you have any child relations that are affected
'by the current table whose row is being deleted. If a DataRelation exists
'it is necessary to Update the Child Table's rows first, before updating the
'Parent Table's Deleted row.
'Here are some examples that are helpful to peruse in the Online Help
'Documentation for VB 2008
Private Sub CommitDeletedRows(ByVal tbl As DataTable, Adapter as SqlDataAdapter)
Dim deletes() As DataRow
Try
'again this section here is useful for understanding how the
'child relations are dependent upon each other
'which again is only possible with a dynamically linked dataadapter
'for each table
'For Each rel As DataRelation In tbl.ChildRelations
' CommitDeletedRows(rel.ChildTable, GetAdapterForTable(rel.ChildTable))
'Next
'End If
deletes = tbl.Select("", "", DataViewRowState.Deleted)
if deletes.length >0 then
Adapter.Update(deletes)
end if
catch
end try
End Sub