using System.Data.SQLite; // specify the database file location string dataSource = "Data Source=myDatabase.sqlite"; // create the connection object SQLiteConnection connection = new SQLiteConnection(dataSource); // open the connection connection.Open();
// create a SQL SELECT statement string query = "SELECT * FROM customers"; // create the command object SQLiteCommand command = new SQLiteCommand(query, connection); // execute the command and get the data reader SQLiteDataReader reader = command.ExecuteReader(); // iterate through the results while (reader.Read()) { // access the data using the field name or index string name = reader["name"].ToString(); int age = (int)reader["age"]; Console.WriteLine("{0} is {1} years old.", name, age); } // close the reader and connection reader.Close(); connection.Close();In this example, we are executing a SQL SELECT statement on the "customers" table and iterating through the results using a data reader. We access the data using the field name or index and print it to the console. Package Library The package library for the System.Data.SQLite SQLiteConnection is the SQLite.NET package. This library can be installed using NuGet package manager in Visual Studio or downloaded from the official website.