从数据库删除记录时出错 [英] Error while deleting record from database

查看:98
本文介绍了从数据库删除记录时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

已删除.如果您调用

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.

这篇关于从数据库删除记录时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆