一、Windows安装
安装绿色版本,步骤如下:
1、访问https://www.sqlite.org/download.html ,从 Windows 区下载预编译的二进制文件。
2、您需要下载 sqlite-tools-win32-*.zip和 sqlite-dll-win32-*.zip压缩文件。
3、创建文件夹 C:\sqlite,并在此文件夹下解压上面两个压缩文件,将得到 sqlite3.def、sqlite3.dll 和 sqlite3.exe 文件,如图:
4、添加 C:\sqlite 到 PATH 环境变量,最后在命令提示符下,任意目录,使用 sqlite3命令,如图:
二、命令
1、添加数据库和表
.open information.db 打开数据库,数据库不存在时就创建;
.databases 查看有哪些数据库;
CREATE TAEBE STUEDNT…:创建表STUDENT;
.schema STUDENT: 查看表的完整信息;
2、表中添加数据
三、C#操作数据库
通过新建控制台程序进行演示。目标框架选择.NET 5.0,通过”管理NuGet程序包”安装依赖项。其中,Dapper是一个ORM框架。
查询数据库调用如下:
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>
四、参考
Original: https://blog.csdn.net/yonglixiangban/article/details/124184642
Author: yonglixiangban
Title: SQLite的基本使用
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/815146/
转载文章受原作者版权保护。转载请注明原作者出处!