.NET to read Data SQLite Database

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.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2025 Pamai Tech