我正在尝试使用ado连接字符串将DB2连接到Excel。请您告诉我代码的错误
它也是我桌面上的本地设置,任何人都可以告诉我如何找到主机名和用户ID。
Sub Import_data_from_db2()
Dim rs As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim sConnString As String
Set rs = New ADODB.Recordset
Set cnn = New ADODB.Connection
' create the connection
sConnString = "Provider=IBMDADB2;Database=Sample;" & _
"Hostname=localhost;Protocol=TCPIP;" & _
"Port=50000;Uid=db2admin;Pwd=xx;"
'Open connection
cnn.Open sConnString
strQry = "SELECT * FROM ORDERS"
With rs
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open strQry, cnn
End With
Sheets(1).Range("A1").CopyFromRecordset rs
End Sub