|
用ADO执行存储过程(ADP中)
Dim rst1 As New ADODB.Recordset
Dim cmdObject As New ADODB.Command
Dim parInput1 As ADODB.Parameter
Dim parInput2 As ADODB.Parameter
Dim parInput3 As ADODB.Parameter
Dim parInput4 As ADODB.Parameter
Dim parOutput1 As ADODB.Parameter 'output
Dim parOutput2 As ADODB.Parameter 'output
Dim strSQL As String
Dim rq2 As String
cmdObject.ActiveConnection = CurrentProject.Connection '设定后端连接
cmdObject.CommandText = "tyms_prt_yzyl_kq" '设定要执行的存储过程名
cmdObject.CommandType = adCmdStoredProc '设定类型为存储过程
'建立输入参数的第一种方法
Set parInput1 = cmdObject.CreateParameter("flh", adVarChar, adParamInput, 100, Me.flh)
cmdObject.Parameters.Append parInput1
Set parInput2 = cmdObject.CreateParameter("rq2", adChar, adParamInput, 10, rq2)
cmdObject.Parameters.Append parInput2
Set parInput3 = cmdObject.CreateParameter("TZDM_all", adVarChar, adParamInput, 200, "a,h,d,ly,")
cmdObject.Parameters.Append parInput3
Set parInput4 = cmdObject.CreateParameter("ck", adChar, adParamInput, 40, Me.ck)
cmdObject.Parameters.Append parInput4
'如果在 Type 参数中指定数字型数据类型(adNumeric 或 adDecimal),也必须设置 NumericScale 和 Precision 属性。
Set parOutput1 = cmdObject.CreateParameter
parOutput1.Name = "yzyl"
parOutput1.Direction = adParamOutput
parOutput1.Type = adVarChar
parOutput1.Size = 18
parOutput1.NumericScale = 18 '******************
parOutput1.Precision = 2 '**********************
cmdObject.Parameters.Append parOutput1
Set parOutput2 = cmdObject.CreateParameter
parOutput2.Name = "kq"
parOutput2.Direction = adParamOutput
parOutput2.Type = adVarChar
parOutput2.Size = 18
parOutput2.NumericScale = 18
parOutput2.Precision = 2
cmdObject.Parameters.Append parOutput2
cmdObject.Execute '运行存储过程
Me.yzyl = parOutput1
Me.kq = parOutput2
Set cmdObject = Nothing |
|