首页 > 代码库 > 加载分页

加载分页

        public List<Customer> LoadPage(string where, int index, int size, out int total, List<DbParameter> args) {
            List<DbParameter> ps = new List<DbParameter>();
            ps.AddRange(args);

            string sql = @"SELECT COUNT(0) as total FROM [dbo].[Customer] WHERE [member_id] != ‘‘ " + where;
            total = Convert.ToInt32(database.ExecuteScalar(sql, ps));

            sql = @"
SELECT
    *
FROM
    [dbo].[Customer]
WHERE
    [member_id] != ‘‘
" + where + @"
ORDER BY ID DESC
OFFSET @p ROWS FETCH NEXT @pz ROWS ONLY";

            List<DbParameter> ps1 = new List<DbParameter>();
            ps1.AddRange(args);
            ps1.Add(new SqlParameter("@p", (index - 1) * size));
            ps1.Add(new SqlParameter("@pz", size));

            return database.ExecuteReader<Customer>(sql, ps1);
        }

加载分页