【发布时间】:2014-03-26 18:08:23
【问题描述】:
我正在查询远程服务器上的数据库,并将结果保存在 Excel 电子表格中。在 A 列中说。
出于这个原因,我创建了一个按钮来允许“随意”操作并开始设置我的 ADODB 对象。
与数据库的连接很好,但是我不清楚如何设置 .Recordset 对象 (MyOutput) 以在 A 列中输出我的查询结果。这是我的代码:
Private Sub RunQuery_Click()
Dim MyOutput As ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim myCommand As ADODB.Command
Dim stringSQL As String
Dim stringConn As String
cnn.Provider = "Microsoft.Jet.OLEDB.4.0;"
cnn.Properties("Jet OLEDB:System database") = "My path"
stringConn = "Data Source=\'my path';User Id='';Password='';"
cnn.Open stringConn
Set myCommand = New ADODB.Command
myCommand.ActiveConnection = cnn
stringSQL = " My query"
myCommand.CommandText = stringSQL
myCommand.Execute
cnn.Close
Set cnn = Nothing
End Sub
我可以在这里帮忙吗?
非常感谢你们的时间!
【问题讨论】: