当我按下删除按钮时遇到此问题我收到此错误"更新需要有效的DeleteCommand,当传递带有已删除行的DataRow集合时。",我正在使用visual basics 2008和microsoft access对于我的节目。
Dim CurrentRowNo As Integer = 0
Dim objDataSet As New DataSet
Dim objDataAdapter As New OleDbDataAdapter("SELECT * FROM Stock", cn)
If objDataTable.Rows.Count > 0 Then
objDataTable.Rows(CurrentRowNo).Delete()
objDataAdapter.Update(objDataTable)
End If
答案 0 :(得分:1)
您没有此数据适配器的DeleteCommand对象。您可以手动创建DeleteCommand,也可以使用CommandBuilder为您生成它们。
检查here以获取有关CommandBuilder对象的更多信息。
(未经测试的航空代码):
Dim CurrentRowNo As Integer = 0
Dim objDataSet As New DataSet
Dim objDataAdapter As New OleDbDataAdapter("SELECT * FROM Stock", cn)
Dim builder as SqlCommandBuilder = New SqlCommandBuilder(objDataAdapter)
builder.QuotePrefix = "["
builder.QuoteSuffix = "]"
If objDataTable.Rows.Count > 0 Then
objDataTable.Rows(CurrentRowNo).Delete()
objDataAdapter.Update(objDataTable)
End If