CREATE Proc pr_test1
as
 select * from tb
GO
该存储过程就返回一个表,
CREATE Proc test2
@id int ,
@uid char(20),
@iMsg char(20)  output  --返回信息
as
if exists (select * from login where id=@id)
begin
update login set uid=@uid where id=@id
set @iMsg='更新成功'
end
else
 set @iMsg = '无此用户'
GO

解决方案 »

  1.   

    感谢楼上的朋友。请问,在程序里,如何获得上面的◎iMsg变量呢?
      

  2.   

    declare @iMsg char(20)
    exec test2 1,10,@imsg output
      

  3.   

    在程序里,如果返回的是表的话,同样用recordset来接收,如果是返回的单个变量的话,也用一个变量来接收就可以了.一般在ado里调用存储过程都用command的吧.
      

  4.   

    Public Function ExecProc( )  As ADODB.Recordset    Dim madcmdCMD As New ADODB.Command 
        Set madrs = New ADODB.Recordset    With madcmdCMD
            .ActiveConnection = Me.myConn               'Connection
            .CommandText = "usp_GetRptCols"             '存储过程名称
            .CommandType = adCmdStoredProc              '存储过程的类型
            .CommandTimeout = 120                       ' default to 120 seconds
             
            .Parameters.Append .CreateParameter("a", adVarChar, adParamInput, 3000, Trim("a"))
            .Parameters.Append .CreateParameter("CountAll", adInteger, adParamOutput)        With madrs
                .CursorLocation = adUseClient   
                .CursorType = adOpenStatic
                .LockType = adLockReadOnly
                .Open madcmdCMD
            End With
        End With
        
        Set ExecProc = madrs
        Exit Function
    }这样就可以了,这个是VB的做法!