使用ADO连接不是更方便?
- Sub test()
- ' 连接Oracle数据库
- Dim cn As ADODB.Connection
- Set cn = New ADODB.Connection
- cn.Open "Provider=MSDAORA.1;Data Source=数据源;User ID=用户名;Password=密码;Persist Security Info=True"
- ' 通过表或者查询创建数据集
- Dim rs As ADODB.Recordset
- Set rs = New ADODB.Recordset
- rs.Open "表名", cn, adOpenKeyset, adLockOptimistic
- MsgBox rs.RecordCount
- rs.Close
- rs.Open "Select 字段 From 表名 Where 条件", cn, adOpenKeyset, adLockOptimistic
- MsgBox rs.RecordCount
- ' 关闭数据集和数据连接
- rs.Close
- Set rs = Nothing
- cn.Close
- Set cn = Nothing
- End Sub
|