【学习笔记】递归算法+sql三种分页

using Maticsoft.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Maticsoft.Web.cest
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        Maticsoft.BLL.lhzExcSQL lhz = new BLL.lhzExcSQL();
        protected void Page_Load(object sender, EventArgs e)
        {
            //Response.Write(Fun(4));
            if (!IsPostBack)
            {
                Fun(30);
            }
        }
        //递归算法    1,1,2,3,5,8,13 求第n位数是多少?
        public int Fun(int n)
        {
            if (n < 1) return 0;
            if (n == 1 || n == 2) return 1;
            else return Fun(n - 1) + Fun(n - 2);
        }
        //三种常见分页
        //DataTable dt = lhz.GetTalbe("select nid,ntitle from news order by nid OFFSET (5 * (1-1)) ROW FETCH NEXT 5 rows only");
        //DataTable dt = lhz.GetTalbe("select top 5 nid,ntitle from news where nid not in (select top 0 nid from news order by nid) order by nid");
        //DataTable dt = lhz.GetTalbe("select * from (select top 5 nid,ntitle,ROW_NUMBER() over(order by nid) r from news) tt where tt.r between 1 and 5");
    }
}

 

posted @ 2018-06-20 17:55  千山慕雪  阅读(326)  评论(0编辑  收藏  举报