奇怪:用adodb.command调用存储过程,没调用refresh,老自动填充上了parameters集合!
具体代码如下:
.......
Set cn = New ADODB.Connection
CNSTR = "Provider=SQLOLEDB.1;Auto Translate=false;Persist Security Info=False;User ID= " & UID & ";Password= " & PWD & ";Initial Catalog= " & DB & ";Data Source= " & SVR
cn.ConnectionString = CNSTR
cn.Open
Set adoCmdWorkMonthChk.ActiveConnection = cn
With adoCmdWorkMonthChk
.CommandType = adCmdStoredProc
.CommandText = "WorkMonthCheck "
End With
'创建参数
'Parameter 0 is the stored procedure Return code.
Set adoprm = adoCmdWorkMonthChk.CreateParameter( "Return ", adInteger, adParamReturnValue, , -1)
adoCmdWorkMonthChk.Parameters.append adoprm
Set adoprm = adoCmdWorkMonthChk.CreateParameter( "refDate ", adDate, adParamInput)
adoCmdWorkMonthChk.Parameters.append adoprm
'给参数赋值
adoCmdWorkMonthChk.Parameters( "refDate ") = datDispDate
'调用存储过程,检查工作月度
adoCmdWorkMonthChk.Execute
调试发现 执行完.CommandText = "WorkMonthCheck "后 adoCmdWorkMonthChk.Parameters.count就是2了;
如果将调用次序改成
.CommandText = "WorkMonthCheck "
.CommandType = adCmdStoredProc
是可以的;
但如果再执行Set adoCmdWorkMonthChk.ActiveConnection = cn;
adoCmdWorkMonthChk.Parameters.count又是2了;
以上adoCmdWorkMonthChk.Parameters.count是2的时候,没有调用parameters.refresh,也没有调用CreateParameter
现在将adodb的引用改成2.0到2.8都试过了,问题依旧;
该程序以前一直运行正常;最近修改了部分代码,结果没有修改的地方都出现了同样的问题;
[解决办法]
调用refresh呢?
[解决办法]
'// 设置输入参数
.Parameters.Item( "@输入参数 ").Value = "值 "
'// 执行存储过程
.Execute
If .Parameters.Item( "@返回参数名称 ").Value = True Then
Else
End If
End With
'// 释放对象
Set adoComm = Nothing