我正在尝试在 .Net Standard 2.0 项目中使用 c# 和 microsoft.data.sqlite 实现 SQLite 数据库。
当我调用 connection.Open() 时,出现了“Method not found: 'IntPtr SQLitePCL.sqlite3.get_ptr()'”错误。
我已经下载了以下 Nuget Packages:
<ItemGroup>
<PackageReference Include="Microsoft.Data.SQLite" Version="2.2.6" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.0.0" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.0.0" />
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.0.0" />
<PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.0.0" />
<PackageReference Include="SQLitePCLRaw.provider.e_sqlite3.netstandard11" Version="1.1.14" />
</ItemGroup>
我按以下方式执行它:
private static SqliteConnection _sqlConnection = new SqliteConnection(@"Data Source = myPath");
public static Int64 InsertTransaction(string stringToInsert)
{
SQLitePCL.Batteries_V2.Init();
StringBuilder sqlToExecute = new StringBuilder();
sqlToExecute.Append("INSERT INTO table");
sqlToExecute.Append("(columnName) ");
sqlToExecute.Append("VALUES(' " + stringToInsert+ "')");
using (SqliteConnection connection = _sqlConnection)
{
connection.Open();
SqliteTransaction transaction = connection.BeginTransaction();
SqliteCommand sqlCommand = new SqliteCommand(sqlToExecute.ToString(), connection, transaction);
sqlCommand.ExecuteNonQuery();
}
}
所有的东西都在构建中。在运行时,当以下代码块执行时,我会得到:"Method not found: 'IntPtr SQLitePCL.sqlite3.get_ptr()'",它位于 Connection.Open();
StringBuilder
- 它并没有为您带来太多价值(因为绝大部分字符串都是硬编码的)。 - mjwills