|
楼主 |
发表于 2010-6-27 17:49
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
不用链接表,直接用代码也可以独占链接后台数据库:- Public Sub DAO独占打开连接()
-
- Dim dbs As DAO.Database
- Dim rst As DAO.Recordset
-
- Set dbs = OpenDatabase("D:\My Documents\db1.mdb", True) ' 第二个参数设为真,即独占
- Set rst = dbs.OpenRecordset("tbl1")
- End Sub
- Public Sub ADO独占打开连接()
- Dim Cnxn As ADODB.Connection
- Dim rstTitles As ADODB.Recordset
- Dim strCnxn As String
- Set Cnxn = New ADODB.Connection
- strCnxn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\db1.mdb;Mode=Share Exclusive;"
- ' Cnxn.Mode = adModeShareExclusive ' 上面的Mode=Share Exclusive规定了独占连接,或者在这里设置Mode属性也可
- Cnxn.Open strCnxn
-
- Set rstTitles = New ADODB.Recordset
- rstTitles.Open "tbl1", Cnxn, adOpenKeyset, adLockOptimistic
-
- End Sub
复制代码 |
|