VB.net:使用MS Access删除datagrid中的所有行

时间:2017-04-06 04:23:52

标签: vb.net

Sub DeleteRecords()

Dim qry As String = "SELECT * FROM Attendance"
Dim daTestTbl As New OleDbDataAdapter(qry, con1)
Dim cbTestTbl As New OleDbCommandBuilder(daTestTbl)
Dim dtTestTbl As New DataTable("Attendance")

Try
    daTestTbl.Fill(dtTestTbl)

    For Each dr As DataRow In dtTestTbl.Rows
        dr.Delete()
    Next

    daTestTbl.Update(dtTestTbl)
    dtTestTbl.Dispose()
    daTestTbl.Dispose()
Catch ex As Exception
    MsgBox(ex.Message)

End Try

运行程序时总会弹出错误。我可以帮忙吗?

这是错误

  

Dynamic SQL Generation for the delete command is not supported against a Select Command that thus not return any key column information.

0 个答案:

没有答案