C# - 为 WPF 应用程序访问 SQLite 数据库

C# - Access SQLite database for WPF application

我已经为 WPF 应用程序创建了设置文件,数据库是 SQLite DB。安装后 SQLite DB 位于 C 文件夹中的此路径,

C:\Program Files (x86)\myCompany\myScanApp.

然后我写了这样的连接字符串来建立与SQLite DB的连接,

static SQLiteConnection dbConnection = new SQLiteConnection(@"Data Source=C:\Program Files (x86)\myCompany\myScanApp\test.s3db;");

然后我再次创建了一个安装文件,然后 运行 在另一台 PC 上创建了这个应用程序。但是,它在 PC 中无法 运行。如何在应用程序中访问数据库?

using(SQLiteConnection conn= new SQLiteConnection(@"Data Source=C:\Program Files (x86)\myCompany\myScanApp\test.s3db;"))
{
    conn.Open();

    SQLiteCommand command = new SQLiteCommand("Select * from yourTable", conn);
    SQLiteDataReader reader = command.ExecuteReader();

    while (reader.Read())
       Console.WriteLine(reader["YourColumn"]);

 
    reader.Close();
}

像这样的东西应该有用。这里整篇文章Getting started with SQLite in C#