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

    技术2022-05-11  70

     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);  }


    最新回复(0)