我已经在网上看过关于如何操作的教程,但是该教程不适用于我希望的程序。本教程告诉您添加4个导航按钮,以便您可以导航数据库(前,后,后和前进)。然后是更新和删除按钮。 但如果这就是我要做的事情,那么导航数据库并更新记录需要10年时间。 现在,我想要做的只是让用户输入一个唯一的ID并点击搜索按钮(我已经完成了)。然后更新会更容易。如何使用此方法更新或删除记录?
答案 0 :(得分:1)
沿着这些方向: -
Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyDatabase.mdb;User Id=admin;Password=;")
Dim cmd As New OleDbCommand
Dim _ID as Integer=1
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = "DELETE FROM blah WHERE primarykey=" & _ID
Using cnn
cnn.open()
cmd.ExecuteNonQuery()
End Using
答案 1 :(得分:-1)
Imports System.Data.OleDb
Dim conn2 As OleDbConnection
Dim DeleteData As OleDbCommand
conn2 = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source="table location here";Persist Security Info=False;")
sql1 = "DELETE * FROM [Audit Log]" ' query for deleting data
conn2.Open() ' openning second connection for clearing purpose
DeleteData = New OleDbCommand(sql1, conn2) 'second connection to remove information from the old table
DeleteData.ExecuteNonQuery()