private cmm as ADODB.Command
private cnn as ADODB.Connectioncnn.open "连接字串"
with cmm
Set .ActiveConnection=cnnOrders
.CommandType=adCmdStoredProc
.CommandText="sp_xxx" '存储过程名
Set rs=.Execute
end with你还可以用Parameters集合来向存储过程来传递参数和取返回值
private cnn as ADODB.Connectioncnn.open "连接字串"
with cmm
Set .ActiveConnection=cnnOrders
.CommandType=adCmdStoredProc
.CommandText="sp_xxx" '存储过程名
Set rs=.Execute
end with你还可以用Parameters集合来向存储过程来传递参数和取返回值
'执行一个标准存储过程
Public Function execSP(sSpname As String) As Integer
On Error GoTo execsp_ERR
Dim Param3 As ADODB.Parameter, Param4 As ADODB.Parameter
Dim Cmd As ADODB.Command
Set Cmd = New ADODB.Command
Cmd.CommandText = sSpname
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTimeout = giTimeout
Cmd.ActiveConnection = gcSqlserverCon
Set Param3 = Cmd.CreateParameter("retcode", adInteger, adParamOutput)
Set Param4 = Cmd.CreateParameter("retmsg", adBSTR, adParamOutput, 30)
Cmd.Parameters.Append Param3
Cmd.Parameters.Append Param4
ChangeMouse (vbHourglass)
Cmd.Execute
ChangeMouse (vbDefault)
execSP = Param3.Value
If Param3.Value = 0 Then
Else
msgbox "【存储过程失败】" & Param4.Value
End If
Cmd.Parameters.Delete Param3.Name
Cmd.Parameters.Delete Param4.Name
Exit Function
execsp_ERR:
ChangeMouse (vbDefault)
msgbox "【存储过程失败】" & Err.Description
execSP = -1
End Function
private cnn as ADODB.Connectioncnn.open "连接字串"
with cmm
Set .ActiveConnection=cnnOrders
.CommandType=adCmdStoredProc
.CommandText="sp_xxx" '存储过程名
.Parameters(1).Type=adChar
.Parameters(1).Size=Len(text1.text)
.Parameters(1).Direction=adParamInput
.Parameters(1).Value=text1.text
'由此类推Parameters(i)
Set rs=.Execute
end with如果用户没有自定义自己的Paramters集合,cmm.Parameters(0)自动保留存储过程的返回值
set cn=new ADODB.connection
Set cmd = New ADODB.Command
With connectdatabase.cmd
.ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = "insertmsg_pack.insert_vehiclemsg"
For i = 0 To 7
.Parameters(i + 1).Type = adChar
.Parameters(i + 1).Size = Len(Text1(i).Text)
.Parameters(i + 1).Direction = adParamInput
.Parameters(i + 1).Value = Text1(i).Text
Next i
.Execute
end with
它说.parameters(i+1) 项目在所需的名称中或序数中未被发现,不知
是怎么回事?
set cn=new ADODB.connection
Set cmd = New ADODB.Command
With connectdatabase.cmd
.ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = "insertmsg_pack.insert_vehiclemsg"
For i = 0 To 7
.Parameters(i + 1).Type = adChar
.Parameters(i + 1).Size = Len(Text1(i).Text)
.Parameters(i + 1).Direction = adParamInput
.Parameters(i + 1).Value = Text1(i).Text
Next i
.Execute
end with
不能导出参数信息,未设置setparametersinfo,这是怎么回事?