I need some help with delete record from database.
I am trying to delete a record from a table in my SQL Server database.
Am I missing something?
Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
_DataSet.Tables(0).Rows(CInt(txtCurrent.Text) - 1).Delete()
' tho, it can remove the deleted rows
' we cannot call the DataSet.AcceptChanges method
' because the DataAdapter would not recognize the delete row
' by the time DataAdapter.Update(DataSet) is called.
EnableNavigation()
cmdSave.Enabled = True ' let user update the underlying database
' after deleting the current record, the current record still points to the
' deleted record (though it cannot be updated).
' The user must MoveNext/Back to view other records.
End Sub
DataRow.Deletedoes not delete this row from database. It marks theDataRow'sRowStateas deleted. This will be checked from aDataAdapterif you callUpdate. If it's state isDeletedit will look for its accordingDeleteCommandwhich you have to provide.So you need to provide a
DeleteCommandfor yourDataAdapterwhich is the sql to delete the row from the database.