GZDBHelper连接SQLite数据库
创建 SQLite测试数据库文件

数据库中 新建一张表 tb_test ,表结构如下

给表增加几条数据

添加Nuget包
nuget包名: System.Data.SQLite.Core 和 System.Data.SQLite.Linq 发送
注意,不要安装 System.Data.SQLite,不然会多出一堆的引用


安装完成后,app.config 中会多出一个sqlite的数据库配置,必须有这个配置,安装 System.Data.SQLite.Linq 引用后才会添加这个配置

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>下载后的引用

连接SQLite数据库
private void btn_testSQLite_Click(object sender, EventArgs e) { // SQLite 文件位置 string dbFile = @"C:\Users\XQ-Garson\Desktop\TestDB.db"; // 生成数据库连接 var connStr = GZDBHelper.ConnectionStrings.BuildSqliteConnectionString(dbFile); // 创建数据库对象 var db = GZDBHelper.DatabaseFactory.CreateDatabase(connStr, GZDBHelper.ConnectionStrings.ProviderNames.ProviderNameForSqlite, null); // 执行SQL获取数据 DataTable data = db.GetTable("select * from tb_test", "tb_test", null); }
GarsonZhang www.yesdotnet.com
如果是 .net standard 或者 .NET Core 则需要使用如下方法 创建数据库对象
var db = GZDBHelper.DatabaseFactory.CreateDatabase(System.Data.SQLite.SQLiteFactory.Instance, connStr, null);
GarsonZhang www.yesdotnet.com
测试获取到的数据

C# SQLite 连接字符串写法
String.Format("Data Source={0};Pooling=true;password={1}", DataSource, Password);版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
GZHelper YES开发框架
