用c#读出存储过程的返回值

来源:互联网 发布:手机预装软件卸载 编辑:程序博客网 时间:2024/06/05 13:24

 public void monitor(){
   int count=0;
   
   
   SqlCommand command=new SqlCommand("proc_check",conn);
   command.CommandType=CommandType.StoredProcedure;

//声明存储过程的参数

   SqlParameter paracount=new SqlParameter("@count",SqlDbType.Int,4);
   paracount.Direction=ParameterDirection.Output;//声明参数的方向

   command.Parameters.Add(paracount);//代入参数
   try
   {
    conn.Open();
    command.ExecuteNonQuery();
    conn.Close();

    count=(int)paracount.Value;//取得参数值
   }
   catch(Exception e){
    Console.WriteLine(e.Message);
   }
   Console.WriteLine(count);
  }