【发布时间】:2020-07-02 21:26:15
【问题描述】:
我正在尝试使用 VBA 从 Excel 运行存储过程,但我收到以下代码的“类型不匹配”错误。我可以执行一个存储过程,其参数作为一个字符串传递给 Command 对象,如下所示?
Function Sproc()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cmd As ADODB.Command
Dim ConnectionString As String
Dim StrSproc As String
ConnectionString = "Provider=SQLOLEDB;Data Source=DBSource;" & _
"Initial Catalog=CurrentDb;" & _
"Integrated Security=SSPI;"
'Opens connection to the database
cnn.Open ConnectionString
'Timeout error in seconds for executing the entire query; this will run for 15 minutes
'before VBA times out, but your database might timeout before this value
cnn.CommandTimeout = 900
StrSproc = "EXEC StoredProcedure " & _
"@parameter1 = 0," & _
"@parameter2 = 0," & _
"@parameter3 = 0,"
Application.StatusBar = "Running stored procedure..."
Set rst = cmd.Execute(, , StrSproc)
End Function
【问题讨论】:
-
您的问题在哪里?在哪一行抛出异常?错误信息是什么?
标签: excel vba stored-procedures