dim comm as ado.command
dim para as ado.参数
dim Rs as ado.recodersetset comm=new ado.command
comm.type=存储过程
comm.commtext=存储过程名称
set para=ado.参数
// 参数的初始设置
comm.append paraset rs=comm.执行
//rs的操作,仅读取rs.close
set rs=nothingset para=nothing
//在执行到下一句时弹出提示框
set comm=nothing//以上代码都顺利执行。
dim para as ado.参数
dim Rs as ado.recodersetset comm=new ado.command
comm.type=存储过程
comm.commtext=存储过程名称
set para=ado.参数
// 参数的初始设置
comm.append paraset rs=comm.执行
//rs的操作,仅读取rs.close
set rs=nothingset para=nothing
//在执行到下一句时弹出提示框
set comm=nothing//以上代码都顺利执行。
dim para as ado.参数
dim Rs as ado.recodersetset comm=new ado.command
comm.type=存储过程
comm.commtext=存储过程名称
set para=ado.参数
// 参数的初始设置
comm.append paraset rs=comm.执行
//rs的操作,仅读取rs.close
set rs=nothingset para=nothing
//在执行到下一句时弹出提示框
set comm=nothing//以上代码都顺利执行。
Function RunSPReturnRS(ByVal strSP, params, ByRef OutArray) On Error GoTo ErrorHandler
' Create the ADO objects
Dim OutPutParms
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
' Init the ADO objects & the stored proc parameters
cmd.ActiveConnection = Conn
cmd.CommandText = strSP
cmd.CommandType = adCmdStoredProc
collectParams cmd, params, OutPutParms
' Execute the query for readonly
rs.CursorLocation = adUseClient
rs.CacheSize = AdCacheSize
rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
If OutPutParms Then OutArray = collectOutputParms(cmd, params)
' Disconnect the recordset and clean up
' Disconnect the recordset
Set cmd.ActiveConnection = Nothing
Set cmd = Nothing
Set rs.ActiveConnection = Nothing ' Return the resultant recordset
Set RunSPReturnRS = rs
Exit FunctionErrorHandler:
RaiseError g_modName, "RunSPReturnRS"
End Function
Private Sub collectParams(ByRef cmd, ByVal argparams, ByRef OutPutParms)
Dim params, v
Dim I, l, u
'if argparams is empty
If Not IsArray(argparams) Then Exit Sub
OutPutParms = False
params = argparams
For I = LBound(params) To UBound(params)
l = LBound(params(I))
u = UBound(params(I))
' Check for nulls.
If u - l >= 3 Then
If VarType(params(I)(4)) = vbString Then
If params(I)(4) = "" Then
v = Null
Else
v = params(I)(4)
End If
Else
v = params(I)(4)
End If
If params(I)(2) = adParamOutput Then OutPutParms = True
cmd.Parameters.Append cmd.CreateParameter(params(I)(0), params(I)(1), params(I)(2), params(I)(3), v)
Else
RaiseError g_modName, "CollectParms"
End If
Next
End Sub
Dim params, v, OutArray(20)
Dim I, l, u
'if argparams is empty
'If Not IsArray(argparams) Then Exit Sub
params = argparams
For I = LBound(params) To UBound(params)
OutArray(I) = cmd.Parameters(I).Value
Next
collectOutputParms = OutArray
End Function
衊?㘓뿶ਸ?Ꮲ뿶ů???ǰĺ儀Ǭ뺤 衊?㘓뿶ਸ?Ď???衊?㘓뿶衊?㘓衊?
//add: comm.close
set comm=nothing//以上代码都顺利执行。
Dim lErr As Long
Dim sErr As String
lErr = VBA.Err.Number
sErr = VBA.Err.Description
App.LogEvent (Err.Description)
Err.Raise lErr, SetErrSource(module, functionName), Err.Description
End Sub
dim rs as adodb.recordset
.
.
.
dim sql as string
sql=" { call 存储过程名(参数列表) }"
rs.open sql,cn这种方法调用最简单