我是这样做的:
点击[工程]→[部件→点击“Microsoft ADO Data Control 6.0 (OLEDB)”前面的□→点击“确定”
点击工具箱中的ADOData控件→在窗体加入该控件
然后:
Private Sub Form_Activate()
‘连接数据库
Dim s As String
s = App.Path & "\assart_1.mdb"
’数据库放在编程文件夹内
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =" + Chr(34) + s + Chr(34) & ";Jet OLEDB:Database Password=ch3523;"
'打开有密码数据库,密码为“ch3523”
'"Data Source =" + Chr(34) + s + Chr(34) & ";Persist Security Info=False"
'打开无密码数据库
End Sub
增加记录代码如下:
Adodc1.Recordset.AddNew
With Adodc1
.Recordset("文件名") = Trim$(Text1(0).Text)
.Recordset("日期") = Trim$(Text1(1).Text)
.Recordset("存档合号") = Trim$(Text1(2).Text)
.Recordset("本合序号") = Trim$(Text1(3).Text)
.Recordset("备注") = Trim$(Text1(4).Text)
.Recordset.Update
End With