Public Conn As New ADODB.Connection
Public HidErr As Boolean
Public RS As New ADODB.Recordset
Public comm As New ADODB.Command
'打开ACCESS数据库,可设定登陆的密码
Function OpenAccess(Mdbfilepath As String, Optional Mdbpassword As String, Optional usemdw As Boolean) As Boolean
'联系QQ:1085992075--需要什么函数或功能,可以联系我。
On Error GoTo err
Dim ConnStr As String
Conn.ConnectionTimeout = 999999999
ConnStr = "Provider=MSDASQL.1Persist Security Info=falseUser ID=saExtended Properties=DRIVER=Microsoft Access Driver (*.mdb)"
If usemdw Then ConnStr = ConnStr &"DBPROP_JETOLEDB_SYSDBPATH=" &Chr(34) &"F:\PROGRA~1\MICROS~2\OFFICE\SYSTEM.MDW" &Chr(34) &"user=adminpass=abc"
ConnStr = ConnStr &"DBQ=" &Mdbfilepath &"Password=" &Mdbpassword
Conn.open ConnStr
OpenAccess = True
Exit Function
err:
If Not HidErr Then
MsgBox err.Number &vbCrLf &err.Description
End If
End Function
'┗〓〓〓〓〓〓〓〓〓 OpenAccess,end 〓〓〓〓〓〓〓〓〓┛
Sub Test()
Dim RS As New ADODB.Recordset
'Set Rs = CreateObject("adodb.recordset")
Dim Sql As String
Sql = "select * from 表1 WHERE USER='" &"李三" &"'"
'OpenAccess函数相关定义声明等 Start
Public Conn As New ADODB.Connection
Public HidErr As Boolean
Public RS As New ADODB.Recordset
Public comm As New ADODB.Command
'OpenAccess函数相关定义声明等 End
'OpenAccess,start
'[详介]:
'函数注释:
'[简介]:
'打开ACCESS数据库,可设定登陆的密码
Function OpenAccess(Mdbfilepath As String, Optional Mdbpassword As String, Optional usemdw As Boolean) As Boolean
'帮你写函数,帮你写代码,帮你写模块,帮你设计软件
'联系QQ:1085992075--需要什么函数或功能,可以联系我。
On Error GoTo err
Dim ConnStr As String
Conn.ConnectionTimeout = 999999999
ConnStr = "Provider=MSDASQL.1Persist Security Info=falseUser ID=saExtended Properties=DRIVER=Microsoft Access Driver (*.mdb)"
If usemdw Then ConnStr = ConnStr &"DBPROP_JETOLEDB_SYSDBPATH=" &Chr(34) &"F:\PROGRA~1\MICROS~2\OFFICE\SYSTEM.MDW" &Chr(34) &"user=adminpass=abc"
ConnStr = ConnStr &"DBQ=" &Mdbfilepath &"Password=" &Mdbpassword
Conn.open ConnStr
OpenAccess = True
Exit Function
err:
If Not HidErr Then
MsgBox err.Number &vbCrLf &err.Description
End If
End Function
'OpenAccess,end
Sub Test()
Dim RS As New ADODB.Recordset
'Set Rs = CreateObject("adodb.recordset")
Dim Sql As String
Sql = "select * from 表1 WHERE USER='" &"李三" &"'"view plaincopy to clipboardprint?
'以上用来查李三这条数据
RS.open Sql, Conn, 1, 3
MsgBox RS(0)
rs(1)="aaa"
'rs.update'保存
End Sub
Private Sub Command1_Click()
OpenAccess APP.PATH &"\1.mdb"
Test
End Sub
一,准备工作:1,建立新工程,保存到文件夹。
2,把ACCESS数据库文件复制到上述文件夹。
3,在窗体上,添加一个ADODC控件和一个按钮。
4,在按钮的单击事件里编写程序。
程序代码如下:
'连接数据库的三步曲:
Adodc1.ConnectionString
=
"Provider=Microsoft.Jet.OLEDB.4.0Data
Source="
&
App.Path
&
"\数据库.mdbPersist
Security
Info=False"
Adodc1.RecordSource
=
"数据表名"
Adodc1.Refresh
‘添加记录
Adodc1.Recordset.AddNew
'添加新的空纪录
Adodc1.Recordset("姓名").Value
=
Text1.Text
Adodc1.Recordset.Update
’更新到数据表
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)