Modern ADO .Net with SQLite in VB and C#

Here we’ll talk about modern ADO.Net with SQLite DB connecting with VB and C# using sample code. Microsoft.Data.Sqlite is a lightweight package for SQLite that runs in.net core environments such as 5/6/7 ADO.net.

Use the following command in the Package Manager Console to install the Microsoft Data. SQLite Package.

Install-Package Microsoft.Data.Sqlite

SQLite with VB Example code.

Imports System
Imports Microsoft.Data.Sqlite

Module Module1
    Sub Main()
        Dim connectionString As String = "Data Source=mydatabase.db"

        Using connection As New SqliteConnection(connectionString)
            connection.Open()

            ' Create a table
            Dim createTableQuery As String = "CREATE TABLE IF NOT EXISTS SampleTable (Id INTEGER PRIMARY KEY, Name TEXT)"
            Using createCommand As New SqliteCommand(createTableQuery, connection)
                createCommand.ExecuteNonQuery()
            End Using

            ' Insert a record
            Dim insertQuery As String = "INSERT INTO SampleTable (Name) VALUES ('John Doe')"
            Using insertCommand As New SqliteCommand(insertQuery, connection)
                insertCommand.ExecuteNonQuery()
            End Using

            ' Read records
            Dim selectQuery As String = "SELECT * FROM SampleTable"
            Using selectCommand As New SqliteCommand(selectQuery, connection)
                Using reader As SqliteDataReader = selectCommand.ExecuteReader()
                    While reader.Read()
                        Console.WriteLine($"Id: {reader("Id")}, Name: {reader("Name")}")
                    End While
                End Using
            End Using
        End Using
    End Sub
End Module

SQLite DB with c# example.

using System;
using Microsoft.Data.Sqlite;
class Program
{
    static void Main()
    {
        string connectionString = "Data Source=mydatabase.db";
        using (var connection = new SqliteConnection(connectionString))
        {
            connection.Open();

            // Create table query
            string createTableQuery = "CREATE TABLE IF NOT EXISTS SampleTable (Id INTEGER PRIMARY KEY, Name TEXT)";
            using (var createCommand = new SqliteCommand(createTableQuery, connection))
            {
                createCommand.ExecuteNonQuery();
            }
            // Insert data query
            string insertQuery = "INSERT INTO SampleTable (Name) VALUES ('John Doe')";
            using (var insertCommand = new SqliteCommand(insertQuery, connection))
            {
                insertCommand.ExecuteNonQuery();
            }
            // Select data query
            string selectQuery = "SELECT * FROM SampleTable";
            using (var selectCommand = new SqliteCommand(selectQuery, connection))
            using (var reader = selectCommand.ExecuteReader())
            {
                while (reader.Read())
                {
                    Console.WriteLine($"Id: {reader["Id"]}, Name: {reader["Name"]}");
                }
            }
        }
    }
}

Output
Best and Most Recommended ASP.NET Core 8.0.11 Hosting

Fortunately, there are a number of dependable and recommended web hosts available that can help you gain control of your website’s performance and improve your ASP.NET Core 8.0.11 web ranking. HostForLIFE.eu is highly recommended. In Europe, HostForLIFE.eu is the most popular option for first-time web hosts searching for an affordable plan.

Their standard price begins at only €3.49 per month. Customers are permitted to choose quarterly and annual plans based on their preferences. HostForLIFE.eu guarantees “No Hidden Fees” and an industry-leading ’30 Days Cash Back’ policy. Customers who terminate their service within the first thirty days are eligible for a full refund.

By providing reseller hosting accounts, HostForLIFE.eu also gives its consumers the chance to generate income. You can purchase their reseller hosting account, host an unlimited number of websites on it, and even sell some of your hosting space to others. This is one of the most effective methods for making money online. They will take care of all your customers’ hosting needs, so you do not need to fret about hosting-related matters.