如何通过ADO VBA提供更新存储过程的十进制input参数(可以为空)
我正在尝试在Excel中创build一个模板,以便客户批量更新SQL Server数据库。
棘手的部分是一些数字列,例如,我正在testing的是Estimated_Amt
。 值可能是空的,我试过,还是不知道是否为空,如何通过这个值来更新存储过程。
以下是我如何设置参数:
Estimated_Amt = .Cells(iRowNo,8) If (.Cells(iRowNo, 8) = "") Then cmd.Parameters.Append cmd.CreateParameter("@Estimated_Amt", adVarChar, adParamInput, DBNULL.Value) Else cmd.Parameters.Append cmd.CreateParameter("@Estimated_Amt", adVarChar, adParamInput, CStr(Estimated_Amt)) End If
我分别尝试了AdDouble
和AdDecimal
,并且没有成功捕获空值或空值,并且使用AdVarchar
仍然无法正确工作
而调用程序部分如下:
cmd.CommandText = "SP_RIBulkyUpdate @CaseNumber = " & CaseNumber & ", " & _ "@Estimated_Amt = " & Estimated_Amt
任何build议正确设置input参数? 谢谢。
而不是DBNULL.Value
,您可以尝试vbNullString
或Null
( https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.constants.vbnullstring ( v= DBNULL.Value
)ie
... cmd.Parameters.Append cmd.CreateParameter("@Estimated_Amt", adVarChar, adParamInput, Null) ...