无法从vb表单中删除数据库/访问中的记录

时间:2014-04-24 04:19:52

标签: vb.net function rows delete-row

我正在尝试执行列表程序,但我的删除按钮无效。这是我的删除按钮:

    Private Sub btnremove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremove.Click
    If MessageBox.Show("Do you really want to remove this task?", _
        "Remove", MessageBoxButtons.YesNo, _
        MessageBoxIcon.Warning) = DialogResult.No Then

        MsgBox("Operation Cancelled")
        Exit Sub
    End If
   Dim cb As New OleDb.OleDbCommandBuilder(da)
    con.Open()
    ds.Tables("todolist").Rows(inc).Delete()
    MaxRows = MaxRows - 1
    ds.AcceptChanges()
    con.Close()
    inc = 0
    NavigateRecords()
    da.Update(ds, "todolist")


End Sub

按下删除按钮后,它只会从我的用户界面中删除,但不会从我的数据库中删除。

1 个答案:

答案 0 :(得分:0)

  Private Sub btnremove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremove.Click
    If MessageBox.Show("Do you really want to remove this task?", _
        "Remove", MessageBoxButtons.YesNo, _
        MessageBoxIcon.Warning) = DialogResult.No Then
        MsgBox("Operation Cancelled")
    Else
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        con.Open()
        ds.Tables("todolist").Rows(inc).Delete()
        MaxRows = MaxRows - 1
        ds.AcceptChanges()
        con.Close()
        inc = 0
        NavigateRecords()
        da.Update(ds, "todolist")
    End If
End Sub

注意:msgbox的默认按钮是NO,如果按NO它不会在msgbox提示符press YES时删除条目,然后代码将进入删除部分,然后只有它将从DB

尝试这个,如果没有作品回来