Here’s a sample code in C# using the .NET framework to read data from a SQLite database
using System; using System.Data.SQLite; namespace SqliteDatabaseReaderExample { class Program { static void Main(string[] args) { // Define the connection string for the SQLite database string connectionString = "Data Source=database.db;Version=3;"; // Define the SQL statement to select data from the SQLite database string sql = "SELECT * FROM Customers"; // Create a new instance of the SQLiteConnection class using (SQLiteConnection connection = new SQLiteConnection(connectionString)) { // Open the connection to the SQLite database connection.Open(); // Create a new instance of the SQLiteCommand class using (SQLiteCommand command = new SQLiteCommand(sql, connection)) { // Create a new instance of the SQLiteDataReader class using (SQLiteDataReader reader = command.ExecuteReader()) { // Print the results to the console while (reader.Read()) { Console.WriteLine("{0}\t{1}\t{2}", reader["FirstName"], reader["LastName"], reader["Email"]); } } } } Console.WriteLine("Data has been read from the SQLite database."); Console.ReadLine(); } } }
In this example, the SQLiteConnection
class is used to create a new instance of the SQLite connection to the SQLite database. The Open
method of the SQLiteConnection
object is used to open the connection. The SQLiteCommand
class is used to create a new instance of the SQL command to select data from the SQLite database. The SQLiteDataReader
class is used to create a new instance of the data reader to read the results of the SQL statement. Finally, the results are printed to the console using a while
loop to iterate through the rows of the data reader.