'''引用 MS ActiveX Data Objects 2.5 Library
Option Explicit
Private Sub Command1_Click() '按钮
Dim Con As Connection
Set Con = New Connection
Con.ConnectionString = "Provider=Microsoft.jet.oledb.4.0data source=D:\db1.mdb" '数据库改为你自己的,如果是sql字符串不同要注意下
Con.Open '打开数据库
Con.Execute ("delete from tb") 'tb改为你要清空的表名
If Con.State = adStateOpen Then Con.Close '关闭数据库连接
Set Con = Nothing
End Sub
窗体上画一command,数据库为a ,表名为bPrivate Sub Command1_Click()
Dim msgQk
msgQk = MsgBox("清空数据库将清除所有数据!", 32 + vbOKCancel, "请选择")
If msgQk = 1 Then
Dim cnDel As New ADODB.Connection
Dim rDel As New ADODB.Recordset
Dim sqlDel1 As String
cnDel.Open "DBQ=" &App.Path &"\a.mdbDriver={Microsoft Access Driver (*.mdb)}"
sqlDel1 = "delete * from b"
cnDel.Execute sqlDel1
MsgBox "数据库清空完成!", 32, "完成"
cndel.close
End If
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)