我在excel vba模块中使用以下代码: 记录集永远不会被创建,记录集为空。 当我尝试检索recordcount时,出现记录集错误 不开放。 我在做什么错了?
Dim Conn为ADODB.Connection,RecordSet为ADODB.RecordSet
Dim Command As ADODB.Command
Dim ConnectionString As String, StoredProcName As String
Dim LoginID As ADODB.Parameter, Entity_Id As ADODB.Parameter
Application.ScreenUpdating = False
Set Conn = New ADODB.Connection
Set RecordSet = New ADODB.RecordSet
Set Command = New ADODB.Command
ConnectionString = "Provider=sqloledb;Data Source=vp-dv-sql;Initial Catalog=Viewpoint;Integrated Security=SSPI;"
On Error GoTo CloseConnection
Conn.Open ConnectionString
StoredProcName = "lc_PM11132_JCCostCashFlow_Report"
With Command
.ActiveConnection = Conn
.CommandType = adCmdStoredProc
.CommandText = StoredProcName
End With
Set LoginID = Command.CreateParameter("@ReportType", adInteger, adParamInput, 10, 1)
Command.Parameters.Append LoginID
Set RecordSet = Command.Execute
Sheets("Top 20 Worst Performing").Range("A1").CopyFromRecordset RecordSet
RecordSet.Close
Conn.Close
On Error GoTo 0
Application.ScreenUpdating = True
Exit Sub
CloseConnection: Application.ScreenUpdating =真 MsgBox“ SQL存储过程未成功执行!”,vbCritical,“ SQL错误” 关闭连接