码迷,mamicode.com
首页 > 数据库 > 详细

VBA连接Oracle12c数据库

时间:2018-09-15 23:21:35      阅读:1131      评论:0      收藏:0      [点我收藏+]

标签:rds   ide   添加组件   操作   添加   string   cells   .com   uri   

1.客户端必须安装对应oracle版本的client

2.excel中按如下操作添加组件

‘请先添加引用:工具-引用-Microsoft ActiveX Data Objects 2.8 ‘Library,Microsoft ActiveX Data Objects Recordset 2.8 Library

 

 

Sub OraLink()

    Dim conn As Object
    Dim rs As Object
    Dim strConn As String
    
    Set conn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.recordset")
  
    strConn = "Provider=OraOLEDB.Oracle.1; user id=joe; password=joe; data source = 192.168.0.118:2001/dbap.com.cn; Persist Security Info=True"

    conn.Open strConn ‘打开数据库
    
    Set rs = conn.Execute("select * from joe.test")
    
    For j = 0 To rs.Fields.Count - 1
      Cells(1, j + 1) = rs.Fields(j).Name
    Next
    
    ‘粘贴结果
    Range("A2").CopyFromRecordset rs
    
  
End Sub

  

VBA连接Oracle12c数据库

标签:rds   ide   添加组件   操作   添加   string   cells   .com   uri   

原文地址:https://www.cnblogs.com/joewancn/p/9652667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!