简体   繁体   中英

C# - Access SQLite database for WPF application

I have create Set up file for WPF application and the database is SQLite DB. After the installation the SQLite DB is located this path in C folder,

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

在此处输入图片说明

Then I have written connection string like this way for establishing a connection to SQLite DB,

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

Then I have created a Setup file again and then run this application on another PC. But, it is failing to run in the PC. How can I access DB in application?

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();
}

Something like this should work. Here whole article Getting started with SQLite in C#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM