1 Private Sub btn查詢_Click() 2 '請先添加引用:工具-引用-Microsoft ActiveX Data Objects 2.8 'Library,Microsoft ActiveX Data Objects Recordset 2.8 Library 3 Dim conn As New ADODB.Connection 4 Dim rs As ADODB.Recordset 5 Dim strConn As String 6 Dim strconn1 As String 7 Set conn = CreateObject("ADODB.Connection") 8 Set rs = CreateObject("ADODB.recordset") 9 strConn = "Driver={Oracle in OraClient11g_home1};Dbq=xxx;Uid=xxx;Pwd=xxx;" 10 'OraClient11g_home1為oracle安裝目錄,Dbq為數據庫名 11 conn.Open strConn '打開數據庫 12 13 End Sub
strConn 為連接數據庫關鍵語句,注意excel與oracle為相同位數,區分32位和64位
Driver={Oracle in OraClient11g_home1}使用oracle數據庫自己的驅動連接oracle數據庫
之前試過 strConnect = "Provider=MSDAORA.1;Password=" + strPassWD + ";Persist Security Info=True;User ID=" + strUserID + ";Data Source=" + strSource
或Provider為Provider=OraOLEDB.Oracle.1都出現了錯誤
錯誤代碼為3706