【ASP.NET开发】ADO.NET调用带输出参数的存储过程

public static void QueryList()
        {
            SqlConnection con = new SqlConnection("数据库连接字符串");
            SqlCommand cmd = new SqlCommand("存储过程名称", con);
            //指定命令的类型
            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter[] para ={
                                     new SqlParameter("参数1",SqlDbType.Int),
                                     new SqlParameter("参数2",SqlDbType.Int),
                                     new SqlParameter("参数3",SqlDbType.Int),
                                     new SqlParameter("参数4",SqlDbType.Int)

            };

            para[0].Value = 3;
            para[1].Value = 4;
            para[2].Direction = ParameterDirection.Output;  //设定参数的输出方向
            para[3].Direction = ParameterDirection.Output;

            cmd.Parameters.AddRange(para);// 将参数加入命令对象
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);

            foreach (DataRow dr in dt.Rows)
            {
                Console.WriteLine(dr[0].ToString());
            }

            int pageCount = Convert.ToInt32(cmd.Parameters[2].Value);
            int rowCount = Convert.ToInt32(cmd.Parameters[3].Value);

            Console.WriteLine("PageCount=" + pageCount + ",rowCount=" + rowCount);
        }

你可能感兴趣的:(数据库,cmd,存储)