I've done this before in C++ by including sqlite.h but is there a similarly easy way in C#?
To establish a database connection to an SQLite database, you need to create a new instance of the PDO class and pass a connection string to the constructor of the PDO object. Because you store the path to the sqlite database file in the Config class, you just simply use it to construct the connection string.
SQLite is an embedded relational database engine. It is a self-contained, serverless, zero-configuration and transactional SQL database engine. SQLite implements most of the SQL-92 standard for SQL. The SQLite engine is not a standalone process. Instead, it is statically or dynamically linked into the application.
Open your Visual Studio and select new project and in Visual C# select "Windows Forms Application" and provide the name as Sqlite and click on OK. Right-click on your application and select "Open folder in your window application" and then go to: BIN -> Debug and extract your application here.
High write volumes: SQLite allows only one write operation to take place at any given time, which significantly limits its throughput. If your application requires lots of write operations or multiple concurrent writers, SQLite may not be adequate for your needs.
I'm with, Bruce. I AM using http://system.data.sqlite.org/ with great success as well. Here's a simple class example that I created:
using System; using System.Text; using System.Data; using System.Data.SQLite; namespace MySqlLite { class DataClass { private SQLiteConnection sqlite; public DataClass() { //This part killed me in the beginning. I was specifying "DataSource" //instead of "Data Source" sqlite = new SQLiteConnection("Data Source=/path/to/file.db"); } public DataTable selectQuery(string query) { SQLiteDataAdapter ad; DataTable dt = new DataTable(); try { SQLiteCommand cmd; sqlite.Open(); //Initiate connection to the db cmd = sqlite.CreateCommand(); cmd.CommandText = query; //set the passed query ad = new SQLiteDataAdapter(cmd); ad.Fill(dt); //fill the datasource } catch(SQLiteException ex) { //Add your exception code here. } sqlite.Close(); return dt; } }
There is also an NuGet package: System.Data.SQLite available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With