哪位大神告诉一下vb6.0怎么调用带2个参数的存储过程,有简单的例子最好。谢谢! 100
3个回答
展开全部
Dim CmdSP
Dim adoRS
Dim adCmdSPStoredProc
Dim adParamReturnValue
Dim adParaminput
Dim adParamOutput
Dim adInteger
Dim iVal
Dim oVal
Dim adoField
Dim adVarChar
'这些值在 VB 中是预定义常量,可以直接调用,但在 VBScript 中没有预定义
adCmdSPStoredProc = 4
adParamReturnValue = 4
adParaminput = 1
adParamOutput = 2
adInteger = 3
adVarChar = 200
iVal = 5
oVal = 3
'建一个command对象
set CmdSP = Server.CreateObject("ADODB.Command")
'建立连结
CmdSP.ActiveConnection = "Driver={SQL Server};server=(local);Uid=sa;Pwd=sa;Database=Pubs"
'定义command 对象调用名称
CmdSP.CommandText = "sp_PubsTest"
'设置command调用类型是存储过程 (adCmdSPStoredProc = 4)
CmdSP.CommandType = adCmdSPStoredProc
'往command 对象中加参数
'定义存储过程有直接返回值,并且是个整数,省缺值是4
CmdSP.Parameters.Append CmdSP.CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue, 4)
'定义一个字符型输入参数
CmdSP.Parameters.Append CmdSP.CreateParameter("@au_lname", adVarChar, adParaminput, 20, "M")
'定义一个整型输入参数
CmdSP.Parameters.Append CmdSP.CreateParameter("@intID", adInteger, adParamInput, , iVal)
'定义一个整型输出参数
CmdSP.Parameters.Append CmdSP.CreateParameter("@intIDOut", adInteger, adParamOutput, oVal)
'运行存储过程,并得到返回记录集
Set adoRS = CmdSP.Execute
'把每个记录打印出来,其中的字段是虚拟的,可以不用管
While Not adoRS.EOF
for each adoField in adoRS.Fields
Response.Write adoField.Name & "=" & adoField.Value & "<br>" & vbCRLF
Next
Response.Write "<br>"
adoRS.MoveNext
Wend
'打印两个输出值:
Response.Write "<p>@intIDOut = “ & CmdSP.Parameters("@intIDOut").Value & "</p>"
Response.Write "<p>Return value = " & CmdSP.Parameters("RETURN_VALUE").Value & "</p>"
'大扫除
Set adoRS = nothing
Set CmdSP.ActiveConnection = nothing
Set CmdSP = nothing
以上代码仅供参考
其实核心的就是如何获得存储过程的返回值
追问
还是没看明白呢,能不能把我发的那个存储过程 做一个呢?我照着样子写试试?麻烦啦。。。
展开全部
Dim a(50) As Integer
Private Sub Command1_Click() '生成并显示原来的数组
Print "原来的数组:"
For i = 1 To 40
a(i) = i
Print a(i);
If i Mod 20 = 0 Then Print
Next i
Print
End Sub
Private Sub Command2_Click() '输入新数据并修改原来数组
Dim x As Integer, k As Integer
Do While x >= 0
x = CInt(InputBox("请输入X(输入负数结束):"))
k = CInt(InputBox("请输入要放到第几个位置(<=40):"))
If x >= 0 Then change x, k
Loop
Print "修改以后的数组:"
For i = 1 To 40
Print a(i);
If i Mod 20 = 0 Then Print
Next i
Print
End Sub
Sub change(x As Integer, k As Integer) '修改数组的子程序(过程)
a(k) = x
End Sub
Private Sub Command1_Click() '生成并显示原来的数组
Print "原来的数组:"
For i = 1 To 40
a(i) = i
Print a(i);
If i Mod 20 = 0 Then Print
Next i
End Sub
Private Sub Command2_Click() '输入新数据并修改原来数组
Dim x As Integer, k As Integer
Do While x >= 0
x = CInt(InputBox("请输入X(输入负数结束):"))
k = CInt(InputBox("请输入要放到第几个位置(<=40):"))
If x >= 0 Then change x, k
Loop
Print "修改以后的数组:"
For i = 1 To 40
Print a(i);
If i Mod 20 = 0 Then Print
Next i
End Sub
Sub change(x As Integer, k As Integer) '修改数组的子程序(过程)
a(k) = x
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询