dim com as adodb.command
cim dap as adodb.parameter
set com =new adodb.command
com.activeconnection=con 'a connection name
com.commandtext="test"
com.commandtype=stordprocedure
set dap=new adodb.parameter
dap.appand com.creatparameter("@name",varchan,adinput,50)
dap("@name")="youname"
com.execute
value=dap("return_value")
我想这样就应该可以了,你可以试一下,好久没用过VB了
cim dap as adodb.parameter
set com =new adodb.command
com.activeconnection=con 'a connection name
com.commandtext="test"
com.commandtype=stordprocedure
set dap=new adodb.parameter
dap.appand com.creatparameter("@name",varchan,adinput,50)
dap("@name")="youname"
com.execute
value=dap("return_value")
我想这样就应该可以了,你可以试一下,好久没用过VB了
On Error Resume Next
Dim param1 As Parameter, param2 As Parameter, param3 As Parameter
cmd.CommandText = Trim(txtStorProcName.Text)
cmd.CommandType = adCmdStoredProc
Set cmd.ActiveConnection = cn
Set param1 = cmd.CreateParameter("dtl_code", adChar, adParamInput, 10, "111")
cmd.Parameters.Append param1
Set param2 = cmd.CreateParameter("color", adChar, adParamInput, 10, "黑")
cmd.Parameters.Append param2
Set param3 = cmd.CreateParameter("ret", adInteger, adParamOutput, 4)
cmd.Parameters.Append param3
cmd.Execute
MsgBox param3.Value
End Sub
'Project1.prj
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\WINNT\System32\stdole2.tlb#OLE Automation
Reference=*\G{00000201-0000-0010-8000-00AA006D2EA4}#2.1#0#..\..\..\..\..\..\Program Files\Common Files\system\ado\msado21.tlb#Microsoft ActiveX Data Objects 2.1 Library
Form=Form1.FRM
IconForm="Form1"
Startup="Form1"
Command32=""
Name="工程1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="tdts"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1[MS Transaction Server]
AutoRefresh=1
'Form1.frm
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "SQL Server存储过程应用示例"
ClientHeight = 4770
ClientLeft = 45
ClientTop = 330
ClientWidth = 6675
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4770
ScaleWidth = 6675
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtPass
Height = 285
Left = 5640
TabIndex = 12
Text = "lyt"
Top = 240
Width = 975
End
Begin VB.TextBox txtUid
Height = 285
Left = 3900
TabIndex = 11
Text = "sa"
Top = 210
Width = 975
End
Begin VB.CommandButton cmdDeleteStorProc
Caption = "删除存储过程"
Enabled = 0 'False
Height = 375
Left = 2520
TabIndex = 8
Top = 4200
Width = 1335
End
Begin VB.CommandButton cmdConnect
Caption = "连接数据库"
Height = 285
Left = 3720
TabIndex = 7
Top = 630
Width = 1455
End
Begin VB.TextBox txtStorProcContent
Height = 3135
Left = 120
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 6
Text = "存储过~1.frx":0000
Top = 960
Width = 6405
End
Begin VB.CommandButton cmdCreateStorProc
Caption = "创建存储过程"
Enabled = 0 'False
Height = 375
Left = 720
TabIndex = 5
Top = 4200
Width = 1335
End
Begin VB.TextBox txtStorProcName
Height = 285
Left = 1200
TabIndex = 4
Text = "spTest"
Top = 600
Width = 1935
End
Begin VB.TextBox txtDataBase
Height = 285
Left = 1200
TabIndex = 2
Text = "Test"
Top = 200
Width = 1935
End
Begin VB.CommandButton cmdExecuteStorProc
Caption = "执行存储过程"
Enabled = 0 'False
Height = 375
Left = 4320
TabIndex = 0
Top = 4200
Width = 1335
End
Begin VB.Label Label4
Caption = "密码"
Height = 255
Left = 4950
TabIndex = 10
Top = 240
Width = 615
End
Begin VB.Label Label3
Caption = "用户"
Height = 255
Left = 3240
TabIndex = 9
Top = 210
Width = 615
End
Begin VB.Label Label2
Caption = "存储过程名:"
Height = 255
Left = 180
TabIndex = 3
Top = 600
Width = 1095
End
Begin VB.Label Label1
Caption = "数据库名称:"
Height = 255
Left = 180
TabIndex = 1
Top = 240
Width = 1155
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim cn As New Connection
Dim cmd As New Command
Dim CreateFlag As BooleanPrivate Sub cmdConnect_Click()
Set cn = Nothing
cn.Open "provider=sqloledb;database=" & Trim(txtDataBase.Text) & ";user id=" & txtUid.Text & ";password=" & txtPass.Text
cmdCreateStorProc.Enabled = True
End SubPrivate Sub cmdCreateStorProc_Click()
If CreateFlag = False Then
Set cmd.ActiveConnection = cn
cmd.CommandText = Trim(txtStorProcContent.Text)
cmd.CommandType = adCmdText
cmd.Execute
cmdExecuteStorProc.Enabled = True
cmdDeleteStorProc.Enabled = True
CreateFlag = True
End If
End SubPrivate Sub cmdDeleteStorProc_Click()
If CreateFlag = True Then
Set cmd.ActiveConnection = cn
cmd.CommandText = "drop procedure " & Trim(txtStorProcName.Text)
cmdDeleteStorProc.Enabled = False
cmdExecuteStorProc.Enabled = False
cmd.CommandType = adCmdText
cmd.Execute
CreateFlag = False
End If
End SubPrivate Sub cmdExecuteStorProc_Click()
On Error Resume Next
Dim param1 As Parameter, param2 As Parameter, param3 As Parameter
cmd.CommandText = Trim(txtStorProcName.Text)
cmd.CommandType = adCmdStoredProc
Set cmd.ActiveConnection = cn
Set param1 = cmd.CreateParameter("dtl_code", adChar, adParamInput, 10, "111")
cmd.Parameters.Append param1
Set param2 = cmd.CreateParameter("color", adChar, adParamInput, 10, "黑")
cmd.Parameters.Append param2
Set param3 = cmd.CreateParameter("ret", adInteger, adParamOutput, 4)
cmd.Parameters.Append param3
cmd.Execute
MsgBox param3.Value
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call cmdDeleteStorProc_Click
End Sub