paras[0].Value = "2011新年红包";
                paras[1].Value = userid;
                paras[2].Value = ParameterDirection.Output;                VnetHome.DataProvider.PSqlClient.ExecuteNonQuery(MVC.Config.SysConfig.M_ConnLetuaner, CommandType.StoredProcedure, strSql, paras);
                
                result = Convert.ToInt32(paras[2].Value);
                Response.Write(result.ToString());
用查询分析器没有问题,是正确的,但是用上面的代码执行的时候返回一直是2,paras[2].Value.ToString() 得到的是 OutPut ,这是为什么呢 ??

解决方案 »

  1.   

    paras[2].Direction = ParameterDirection.Output;
      

  2.   

    存储过程中 只执行  set @t_r = 1  结果也是一样的,result = Convert.ToInt32(paras[2].Value.ToString());则会报错
      

  3.   

    把问题说清楚,还有不知你存储过程何模样,另外既然是输出的就得设置Direction 
      

  4.   

    存储过程怎么写
    using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ToString()))
    {
    conn.Open();
    SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
    MyCommand.CommandType = CommandType.StoredProcedure;
    MyCommand.Parameters.Add(new SqlParameter("@a", SqlDbType.Int));
    MyCommand.Parameters["@a"].Value = 20;
    MyCommand.Parameters.Add(new SqlParameter("@b", SqlDbType.Int));
    MyCommand.Parameters["@b"].Direction = ParameterDirection.Output;
    MyCommand.ExecuteNonQuery();
    Response.Write(MyCommand.Parameters["@b"].Value.ToString());
      

  5.   

    关闭连接后,取值
    paras[0].Value = "2011新年红包";
      paras[1].Value = userid;
      paras[2].Value = ParameterDirection.Output;  VnetHome.DataProvider.PSqlClient.ExecuteNonQuery(MVC.Config.SysConfig.M_ConnLetuaner, CommandType.StoredProcedure, strSql, paras);
        conn.close();  // 具体你咋写的不知道,你看自己适当改一下
      result = Convert.ToInt32(paras[2].Value);
      Response.Write(result.ToString());
      

  6.   

    paras[2].Direction = ParameterDirection.Output;  不是value
      

  7.   

    paras[2].Direction = ParameterDirection.Output;
      

  8.   

    paras[2].Direction = ParameterDirection.Output;存储过程 定义了@t_r int Output 这样不会错的 估计你没定义把