winform中SQLite的分页

前端之家收集整理的这篇文章主要介绍了winform中SQLite的分页前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

winform中用到的分页控件这里用:http://cyq1162.blog.51cto.com/2127378/896084

也可以在这下载: 点击下载分页控件

原文中的用法

        private void StartForm_Load(object sender,EventArgs e)
        {
            //创建文件数据库表。
            MDataTable.CreateSchema("Users.txt",false,new string[] { "UserName","Password","Enabled" },sqlDbType.NVarChar,sqlDbType.Bit);
            for (int i = 0; i < 200; i++)//插入200条数据。
            {
                using (MAction action = new MAction("Users.txt","Txt Path={0}"))
                {
                    action.Set("UserName","UserName_" + i);
                    action.Set("Password","Password_" + i);
                    action.Set("Enabled",i%2==0);
                    action.Insert(InsertOp.None);
                }
            }
            pagerControl1.OnPageChanged += new EventHandler(pagerControl1_OnPageChanged);
            LoadData();
        }

        void pagerControl1_OnPageChanged(object sender,EventArgs e)
        {
            LoadData();
        }
        void LoadData()
        {
            int count;
            using (MAction action = new MAction("Users.txt","Txt Path={0}"))
            {
                action.Select(pagerControl1.PageIndex,pagerControl1.PageSize,string.Empty,out count).Bind(gvUsers);
                pagerControl1.DrawControl(count);
            }
        }

sqlite的分页sql语句为

select * from 表 where 条件 order by 列 limit 10,20;

表示跳过10行,取20行的返回结果。

把控件添加页面后,参考上面代码改写为:
        public Form2()
        {
            InitializeComponent();

            pagerControl1.OnPageChanged += new EventHandler(pagerControl1_OnPageChanged);
            LoadData();
        }

        void LoadData()
        {
            pagerControl1.PageSize = 50;
            string sql = string.Format("select * from tb limit {0},{1}",(pagerControl1.PageIndex-1) * pagerControl1.PageSize,pagerControl1.PageSize);
            DataTable dt = sqliteHelper.ExecDataSet(sql).Tables[0];                  
            dataGridView1.DataSource = dt;
            int count = sqliteHelper.ExecuteScalar("select count(*) from tb");     
            pagerControl1.DrawControl(count);
           
        }
        private void pagerControl1_OnPageChanged(object sender,EventArgs e)
        {
            LoadData();
        }
原文链接:https://www.f2er.com/sqlite/201562.html

猜你在找的Sqlite相关文章