lashja
lashja

Reputation: 493

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.

enter image description here

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?

Upvotes: 0

Views: 11089

Answers (1)

mybirthname
mybirthname

Reputation: 18127

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#

Upvotes: 3

Related Questions