NUGET引用
System.Data.SQLite.Core
System.Data.SQLite.Linq
安装System.Data.SQLite.Linq后,会生成一个app.config文件,
<?xml version="1.0" encoding="utf-8"?> <configuration> <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>
安装GZDBHelper:
public class GZDbParameterSQLite : GZDbParameter { public void AddParameter(string parameterName, System.Data.DbType dbType, object value) { SQLiteParameter p = new SQLiteParameter(parameterName, dbType); p.Value = value; this.AddParameter(p); } }
StringBuilder sql = new StringBuilder(); sql.AppendLine("INSERT INTO tb_files(type,fileName)"); sql.AppendLine("VALUES(@type,@fileName)"); GZDbParameterSQLite parms = new GZDbParameterSQLite(); parms.AddParameter(new SQLiteParameter("@type", System.Data.DbType.String, type)); parms.AddParameter(new SQLiteParameter("@fileName", System.Data.DbType.String, fileName)); DBSQLite.Context.ExecuteNonQuery(sql.ToString(), parms);