Public Function ConOra()
'使用函数连接oracle数据库
On Error GoTo ErrMsg:
Dim ConnDB As ADODB.Connection
Set ConnDB = New ADODB.Connection
Dim ConnStr As String
Dim DBRst As ADODB.Recordset
Set DBRst = New ADODB.Recordset
Dim SQLRst As String
Dim OraOpen As Boolean
OraOpen = False
OraID = "ehrdb1" 'Oracle数据库的相关配置
OraUsr = "ehr"
OraPwd = "bbenqehr"
ConnStr = "Provider = MSDAORA.1;Password=" & OraPwd & _
";User ID=" & OraUsr & _
";Data Source=" & OraID & _
";Persist Security Info=True"
ConnDB.CursorLocation = adUseServer
ConnDB.Open ConnStr
OraOpen = True '成功执行后,数据库即被打开
'MsgBox "Connect to the oracle database Successful!", vbInformation, "Connect Successful"
DBRst.ActiveConnection = ConnDB
DBRst.CursorLocation = adUseServer
DBRst.LockType = adLockBatchOptimistic
'向oracle数据库插入数据
ConnDB.Execute ("insert into vendor values('5','匹配')")
'从oracle数据库查询数据
SQLRst = "Select * From vendor"
DBRst.Open SQLRst, ConnDB, adOpenStatic, adLockBatchOptimistic
DBRst.MoveFirst
Sheets("sheet1").Select
Range("A2").Select
ActiveCell.CopyFromRecordset DBRst
Set DBRst = Nothing
Set ConnDB = Nothing
OraOpen = False
Exit Function
ErrMsg:
OraOpen = False
MsgBox "Connect to the oracle database fail ,please check!", vbCritical, "Connect fail!"
End Function
VBA连接ORA,环境EXCEL2013,win8(64位),oracle db11g, 从网上取的代码,修改后运行直接MsgBox,未报错
答案:2 悬赏:10 手机版
解决时间 2021-02-21 01:25
- 提问者网友:抽煙菂渘情少年
- 2021-02-20 14:38
最佳答案
- 五星知识达人网友:迟山
- 2021-02-20 15:20
未报错,但又怎样了,你想问什么问题?
全部回答
- 1楼网友:掌灯师
- 2021-02-20 15:52
同问。。。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯