|
Private Sub CommandButton3_Click()
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cnnStr As String, myTable As String, i As Integer
myTable = "2013_Q" '指定数据表
'设置建立与Oracle数据库服务器中连接的字符串
cnnStr = "Provider=MSDAORA;" _
& "Data Source=xxzx;" _
& "User ID=zcj;" _
& "Password=1234;"
cnn.ConnectionString = cnnStr
cnn.Open
'创建查询记录集
rs.Open Source:=myTable, ActiveConnection:=cnn
'复制记录
With rs
For i = 1 To .Fields.Count '复制字段名
Cells(1, i) = .Fields(i - 1)
Next i
Range("A2").CopyFromRecordset rs '复制记录数据
.Close '关闭记录集
End With
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
|
|