C#基于数据库存储过程的AJAX分页实例

2019-12-26 12:06:16王旭

using System.Data;  
using System.Reflection;  
  
namespace LLSql.DAL  
{  
    public class SqlHelper  
    {  
        /// <summary>  
        /// 获取连接数据库字符串  
        /// </summary>  
        private static string connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;  
        public static DataTable ExecuteProcPageList(int pageSize, int currentPage, out int rowCount, out int pageCount)  
        {  
            using (SqlConnection conn = new SqlConnection(connStr))  
            {  
                conn.Open();  
                using (SqlCommand cmd = conn.CreateCommand())  
                {  
                    cmd.CommandText = "proc_location_paging"; //存储过程的名字  
                    cmd.CommandType = CommandType.StoredProcedure; //设置命令为存储过程类型(即:指明我们执行的是一个存储过程)
                    rowCount = 0;  
                    pageCount = 0;//这里随便给rowCount,pageCount赋个值,因为使用out传递参数的时候,在方法内部一定要给out参数赋值才能用它,但是虽然这里给它赋初值了,但是在执行存储过程中,存储过程又会给这两个参数赋值,并返还回来给我们,那个才是我们要值  
                    SqlParameter[] parameters ={  
                             new SqlParameter("@pageSize",pageSize),  
                             new SqlParameter("@currentpage",currentPage),