首页 > 代码库 > 步步为营-58-SQLite的使用

步步为营-58-SQLite的使用

说明:文档型关系数据库,多用于移动端

1.1 添加引用

 ` 1.1.1  System.Data.SQLite.xml

  1.1.2  System.Data.SQLite.dll

1.2 连接字符串的设置

            string connStr = @"data source=F:\Users\home\Documents\Visual Studio 2013\PaoDingJieNiu\PDJN.db;version=3;"; 

技术分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Fuxi
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //00 构造数据的集合
            List<ManagerInfo> listManager = new List<ManagerInfo>( );
            //01-显示数据
            //01-01 连接字符串"物理路径;版本号":
            string connStr = @"data source=F:\Users\home\Documents\Visual Studio 2013\PaoDingJieNiu\PDJN.db;version=3;";
            //01-02 创建连接字符串
            using (SQLiteConnection conn = new SQLiteConnection( connStr))
            {
                //01-03 查询语句
                SQLiteCommand cmd = new SQLiteCommand("select * from ManagerInfo",conn);
                //01-04 执行command 
                conn.Open();
                SQLiteDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        listManager.Add(new ManagerInfo()
                        {
                            Mid = Convert.ToInt32(reader["mid"]),
                            Mname = reader["mname"].ToString(),
                            Mpwd = reader["mpwd"].ToString(),
                            Mtype =Convert.ToInt32( reader["mtype"])
                        });
                    } 
                }
                //02 显示到datagridView上
                dataGridView1.DataSource = listManager;
            }
        }
    }
}
代码示例
技术分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fuxi
{
   public partial class ManagerInfo
    {
        public int Mid { get; set; }
        public string Mname { get; set; }
        public string Mpwd { get; set; }
        public int Mtype { get; set; }
    }
}
ManagerInfo

技术分享

步步为营-58-SQLite的使用