Excel vba SQL使用输入参数调用的存储过程

时间:2018-02-06 20:25:24

标签: excel vba excel-vba stored-procedures input-parameters

提前谢谢你。我试图从excel运行存储过程接受输入参数,它给出错误运行时错误'-2147217900(80040e14)'自动化错误。

   Set cmd1 = New ADODB.Command
             With cmd1
             .ActiveConnection = sConnString
             .CommandText = "spGetPriceChangeTest"
             .CommandType = adCmdStoredProc
             .CommandTimeout = 360
             .Parameters.Append .CreateParameter("@suppliercode", adVariant, adParamInput, , Range("A" & (x + 2)).Value)
             .Parameters.Append .CreateParameter("@date1", adDBTimeStamp, adParamInput, , datetime)
             .Parameters.Append .CreateParameter("@proddescription", adVariant, adParamInput, , Range("D" & (x + 1)).Value)
             .Parameters.Append .CreateParameter("@vendorcode", adVariant, adParamInput, , Range("C" & (x + 2)).Value)
             .Parameters.Append .CreateParameter("@type", adVariant, adParamInput, , Range("B" & (x + 2)).Value)
             End With
             Set rst1 = New ADODB.Recordset
             Set rst1 = cmd1.Execute

2 个答案:

答案 0 :(得分:1)

创建参数时,请确保在.CreateParameter(“”,adVarchar, 10 ,值)中提及SQL中定义的大小

这篇文章有帮助。它讨论了我们如何详细捕获错误。

https://support.microsoft.com/en-us/help/167957/info-extracting-error-information-from-ado-in-vb

答案 1 :(得分:0)

尝试使用EXEC

.CommandText = "exec spGetPriceChangeTest"