从数据库删除记录时出错

从数据库删除记录时出错

问题描述:

我需要一些有关从数据库中删除记录的帮助.

I need some help with delete record from database.

我正在尝试从SQL Server数据库中的表中删除一条记录.

I am trying to delete a record from a table in my SQL Server database.

我错过了什么吗?

  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

已删除.如果您调用 DeleteCommand ,您必须提供.

DataRow.Delete does not delete this row from database. It marks the DataRow's RowState as deleted. This will be checked from a DataAdapter if you call Update. If it's state is Deleted it will look for its according DeleteCommand which you have to provide.

因此,您需要提供一个 DeleteCommand 表示您的DataAdapter,这是从数据库中删除行的SQL.

So you need to provide a DeleteCommand for your DataAdapter which is the sql to delete the row from the database.