如何调用输出参数的存储过程 
  在数据库中调用

解决方案 »

  1.   

    http://topic.csdn.net/t/20030527/10/1838677.html
    看看对你有用没。
      

  2.   


    string sConnectionString =User ID=zdp;pwd=zdp;Initial Catalog=aaa;Data Source=(local);
    SqlConnection conn=new SqlConnection(sConnectionString); 
    conn.Open();
    SqlCommand cm=new SqlCommand(aaaa,conn);
    cm.CommandType=CommandType.StoredProcedure;
    cm.Parameters.Add(@id,SqlDbType.Int,4);
    cm.Parameters.Add(@test,SqlDbType.Int,4);
    cm.Parameters.Add(@ouid,SqlDbType.Int,4);
    cm.Parameters[@id].Value=Convert.ToInt32(newid.Text.ToString());
    cm.Parameters[@test].Direction=System.Data.ParameterDirection.ReturnValue;
    cm.Parameters[@ouid].Direction=System.Data.ParameterDirection.Output;
    cm.ExecuteNonQuery();
    //OUTRET为存储过程中输出参数给变量outret赋予的值
    string outret=cm.Parameters[@ouid].Value.ToString();
    //returnvalue为存储过程给返回值变量returnvalue赋予的值
    string returnvalue=cm.Parameters[@test].Value.ToString();
    //mes,ret是两个LABEL的ID
    mes.Text=outret.ToString();
    ret.Text=returnvalue.ToString();//-----------------------------------存储过程CREATE PROCEDURE aaaa
    @id INT,
    @ouid int output
    AS
    SET NOCOUNT ON
    begin
    if exists(select * from yg where id=@id)
    BEGIN
    set @ouid=@id
    return 0
    END
    set @ouid=@id
    RETURN 1
    end
    GO@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    create procedure sp_output
    @out int=1 output
    as
    set @out=22
    SqlConnection conn=new SqlConnection(@"server=blackant\db;database=master;uid=sa;pwd=不告诉你");
    SqlCommand comm=new SqlCommand("sp_output",conn);
    comm.CommandType=CommandType.StoredProcedure;
    SqlParameter param=new SqlParameter("@out",SqlDbType.Int);param.Direction=ParameterDirection.Output;
    comm.Parameters.Add(param);
    conn.Open();comm.ExecuteNonQuery();
    conn.Close();
    Console.WriteLine("Value:{0}",param.Value);
      

  3.   

     我数据库的调用方法 ....
    在sql 中怎么调用..
      

  4.   

    有点懵,你要数据库调用C#方法?
    还是 PL/SQL中的一个存储想要调用 另一个有输出参数的存储过程
      

  5.   

    在数据库中function和proc是一样调用的
    exec functionName 参数
      

  6.   

    declare total int output
    exec xxxx 20,1,'0','', total 
    total 哪个接受的是输出参数  
      上面的 哪个是错误的 该怎么改?
     我说的是在sql中的调用 跟程序没一点关系
      

  7.   


    declare total int 
    exec xxxx 20,1,'0','', total output
      

  8.   

    消息 155,级别 15,状态 2,第 1 行
    'int' 不是可以识别的 CURSOR 选项。
    消息 179,级别 15,状态 1,第 2 行
    向存储过程传递常量时不能使用 OUTPUT 选项。
      

  9.   


    declare total int 
    exec SqlDataPaging 'Module','*','ModuleID',20,1,'0','', total output
    消息 155,级别 15,状态 2,第 1 行
    'int' 不是可以识别的 CURSOR 选项。
    消息 179,级别 15,状态 1,第 2 行
    向存储过程传递常量时不能使用 OUTPUT 选项。
      

  10.   

    declare total int  
    exec xxxx 20,1,'0','', total 
    select total
      

  11.   

    create procedure pro @param int output
    as
    --...........declare @i int 
    exec pro  @i output
    select @i
      

  12.   


    消息 155,级别 15,状态 2,第 1 行
    'int' 不是可以识别的 CURSOR 选项。

    还是有这个错误 到底是什么错啊 
      

  13.   

    问题已解决  、定义变量toal时需要在前面加@,而且declare @ 就好了