SQLite的基本使用

一、Windows安装

安装绿色版本,步骤如下:

1、访问https://www.sqlite.org/download.html ,从 Windows 区下载预编译的二进制文件。

2、您需要下载 sqlite-tools-win32-*.zipsqlite-dll-win32-*.zip压缩文件。

3、创建文件夹 C:\sqlite,并在此文件夹下解压上面两个压缩文件,将得到 sqlite3.def、sqlite3.dll 和 sqlite3.exe 文件,如图:

SQLite的基本使用

4、添加 C:\sqlite 到 PATH 环境变量,最后在命令提示符下,任意目录,使用 sqlite3命令,如图:

SQLite的基本使用

二、命令

1、添加数据库和表

SQLite的基本使用

.open information.db 打开数据库,数据库不存在时就创建;

.databases 查看有哪些数据库;

CREATE TAEBE STUEDNT…:创建表STUDENT;

.schema STUDENT: 查看表的完整信息;

2、表中添加数据

SQLite的基本使用

三、C#操作数据库

通过新建控制台程序进行演示。目标框架选择.NET 5.0,通过”管理NuGet程序包”安装依赖项。其中,Dapper是一个ORM框架。

SQLite的基本使用

查询数据库调用如下:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using Dapper;

namespace AccessDB
{
    class Student
    {
        public int ID;
        public string NAME;
        public string SEX;
    }

    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = "data source=F:\\Workspace\\SQLite\\information.db;version=3;";
            using (IDbConnection conn = new SQLiteConnection(connectionString))
            {
                conn.Open();
                IEnumerable<student> students = conn.Query<student>("select * from student", new DynamicParameters());
            }
        }
    }
}
</student></student>

四、参考

  1. SQLite 安装 | 菜鸟教程
  2. C#利用Dapper实现对SQLite的操作_BBBMouse的博客-CSDN博客_dapper sqlite

Original: https://blog.csdn.net/yonglixiangban/article/details/124184642
Author: yonglixiangban
Title: SQLite的基本使用

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/815146/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球