建立要返回的parameter时,设置方向是ouput。

解决方案 »

  1.   

    错误信息 ,就是得不到  存储过程 的返回值 ,我断点   x=(int)myCommand.SelectCommand.Parameters["@ReturnValue"].Value,x还是 2, 正确的返回 要么是 1 要么是 0
    ---------
    declare @test int 
    exec @test=login '12345','12345',@test
    print @test
    测试存储过程 没有错误,我认为我的代码写错了,得到返回值怎么写啊?
      

  2.   

    public bool execProc(string user,string pwd)
    {
    int x=2;
    SqlConnection conn=new SqlConnection("server=localhost;uid=sa;pwd=myping;database=customers;Trusted_Connection='no';");
    try
    {
    SqlDataAdapter myCommand = new SqlDataAdapter("Login", conn); myCommand.SelectCommand.CommandType = CommandType.StoredProcedure; myCommand.SelectCommand.Parameters.Add(new SqlParameter("@UserID", SqlDbType.NVarChar, 15));
    myCommand.SelectCommand.Parameters["@UserID"].Value = user; myCommand.SelectCommand.Parameters.Add(new SqlParameter("@Password", SqlDbType.NVarChar, 4));
    myCommand.SelectCommand.Parameters["@Password"].Value = pwd;

    myCommand.SelectCommand.Parameters.Add (new SqlParameter("@ReturnValue", SqlDbType.Int , 4, System.Data.ParameterDirection.Output,true,1,0,"@ReturnValue",DataRowVersion.Default,x)); myCommand.SelectCommand.Connection=conn;  
    conn.Open(); 
    myCommand.SelectCommand.ExecuteNonQuery();
    DataMsg.Visible=true;  

     x=(int)myCommand.SelectCommand.Parameters["@ReturnValue"].Value ;
     
    //DataSet ds = new DataSet();
    conn.Close(); 
    }
    catch(Exception e)
    {
    DataMsg.Text="Database Error="+e.ToString();
    conn.Close();
    }finally

    if(conn.State==ConnectionState.Open)
    conn.Close();
    }  
    DataMsg.Text+= x.ToString()+"测试";
    if(x==1)
    return true;
    else
    return false;
    }
    ========CREATE procedure Login 
    @userid varchar(15),@password varchar(15),@ReturnValue int outputas
       if exists(select * from customerInfo where  productid=@userid and password=@password)
     
    return 1
    else
     return 0
    GO
    ====================
    能帮我 分析吗?