• 大小: 3.23MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-28
  • 语言: C#
  • 标签: C#  sqlite  分页显示  源码  

资源简介

资源清单: 1.源码:C#访问Sqlite数据库并分页显示。 2. 教程文档:该项目开发的详细步骤,并添加了必要的说明。 3. 使用说明文档:该源码项目的使用说明和注意事项。 4. sqlite.Net。程序运行的必要安装软件。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;

namespace CShape_Sqlite
{
    public partial class Form1 : Form
    {

        DataTable stuDT = new DataTable();

        int pageSize = 0;
        int total = 0;
        int pageCount = 0;
        int pageCurrent = 0;
        int currentRow = 0;

        public Form1()
        {
            InitializeComponent();
        }

        /*查询数据库*/
        public DataTable SelectDB()
        {
            string dbPath = “DB//studentInfo.db3“;

            /*打开数据库连接*/
            string strconn = “Data Source = “ + dbPath + “;“;
            SQLiteConnection sqlconn = new SQLiteConnection(strconn);  //创建连接
            sqlconn.Open();                                            //打开连接

            /*执行sql命令*/
            string strSQL = “select * from studentInfo“;
            SQLiteDataAdapter sqd = new SQLiteDataAdapter(strSQL sqlconn);
            DataTable dt = new DataTable();
            sqd.Fill(dt);                                              //将SQL语句执行结果放入dt中

            /*关闭连接*/
            sqlconn.Close();

            return dt;
        }

        private void button1_Click(object sender EventArgs e)
        {
            stuDT = SelectDB();

            /*处理数据库无数据的情况*/
            if (stuDT == null || stuDT.Rows.Count == 0)
            {
                MessageBox.Show(“没有学生信息可显示!“);
            }

            /*为dataGridView1绑定数据源*/
            else
            {
                InitDataSet();
                //this.dataGridView1.DataSource = stuDT;
            }
        }

        /*初始化显示页面*/
        private void InitDataSet()
        {
            pageSize = 10;      //设置页面行数
            total = stuDT.Rows.Count;
            pageCount = (total / pageSize);    //计算出总页数

            if ((total % pageSize) > 0)
            {
                pageCount++;
            }
            pageCurrent = 1;    //当前页数从开始
            currentRow = 0;     //当前记录数从开始

            /*载入DataTable保存的数据库信息*/
            LoadData();
        }

        /*载入DataTable保存的数据库信息*/
        private void LoadData()
        {
            int nStartPos = 0;   //当前页面开始记录行
            int nEndPos = 0;     //当前页面结束记录行

            DataTable dtTemp =  this.stuDT.Clone();   //克隆DataTable结构框架

            if (pageCurrent == pageCount)
            {
                nEndPos = total;
            }
            else
            {
                nEndPos = pageSize * pageCurrent;
            }
            nStartPos = currentRow;

            /*将对应信息显示在菜单栏和总数统计Label中*/
            toolStripLabel2.Text = “/ “ + pageCount.ToString();
            if (stuDT.Rows.Count == 0)
            {
                toolStripTextBox1.Text = “0“;
            }
            else
            {
             

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        928  2013-05-31 14:02  CShape_Sqlite\CShape_Sqlite.sln

    ..A..H.     14336  2013-05-31 18:11  CShape_Sqlite\CShape_Sqlite.suo

     文件       3647  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\CShape_Sqlite.csproj

     文件        472  2013-05-31 14:02  CShape_Sqlite\CShape_Sqlite\Program.cs

     文件      92102  2013-05-31 18:05  CShape_Sqlite\CShape_Sqlite\stu.ico

     文件       5350  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\Form1.cs

     文件      10590  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\Form1.Designer.cs

     文件     144887  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\Form1.resx

     文件       5612  2013-05-31 14:02  CShape_Sqlite\CShape_Sqlite\Properties\Resources.resx

     文件        249  2013-05-31 14:02  CShape_Sqlite\CShape_Sqlite\Properties\Settings.settings

     文件       1188  2013-05-31 14:02  CShape_Sqlite\CShape_Sqlite\Properties\AssemblyInfo.cs

     文件       2882  2013-05-31 14:02  CShape_Sqlite\CShape_Sqlite\Properties\Resources.Designer.cs

     文件       1098  2013-05-31 14:02  CShape_Sqlite\CShape_Sqlite\Properties\Settings.Designer.cs

     文件       5632  2005-11-11 22:25  CShape_Sqlite\CShape_Sqlite\bin\Debug\CShape_Sqlite.vshost.exe

     文件     208896  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\bin\Debug\CShape_Sqlite.exe

     文件      28160  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\bin\Debug\CShape_Sqlite.pdb

     文件       3072  2013-05-31 15:53  CShape_Sqlite\CShape_Sqlite\bin\Debug\DB\studentInfo.db3

     文件        988  2013-05-31 18:11  CShape_Sqlite\CShape_Sqlite\obj\CShape_Sqlite.csproj.FileListAbsolute.txt

     文件       4631  2013-05-31 15:24  CShape_Sqlite\CShape_Sqlite\obj\Debug\ResolveAssemblyReference.cache

     文件      92668  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\obj\Debug\CShape_Sqlite.Form1.resources

     文件        180  2013-05-31 15:24  CShape_Sqlite\CShape_Sqlite\obj\Debug\CShape_Sqlite.Properties.Resources.resources

     文件     208896  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\obj\Debug\CShape_Sqlite.exe

     文件      28160  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\obj\Debug\CShape_Sqlite.pdb

     文件        842  2013-05-31 18:08  CShape_Sqlite\CShape_Sqlite\obj\Debug\CShape_Sqlite.csproj.GenerateResource.Cache

     文件       3072  2013-05-31 15:53  CShape_Sqlite\CShape_Sqlite\DB\studentInfo.db3

     文件    3172352  2013-04-18 21:32  CShape_Sqlite\附加文件\SQLite-1.0.66.0-setup.exe

     文件     470528  2013-05-31 18:11  CShape_Sqlite\附加文件\C#连接sqlite分页显示实用教程.doc

     文件        429  2013-05-31 18:16  CShape_Sqlite\项目使用说明.txt

     目录          0  2013-05-31 15:24  CShape_Sqlite\CShape_Sqlite\bin\Debug\DB

     目录          0  2013-05-31 14:02  CShape_Sqlite\CShape_Sqlite\obj\Debug\TempPE

............此处省略12个文件信息

评论

共有 条评论