Home > Enterprise >  Why System.Data.Sqlite is not displayed in References?
Why System.Data.Sqlite is not displayed in References?

Time:10-12

I installed SQLite NuGet package using :

PM> NuGet\Install-Package SQLite -Version 3.13.0

Tentative de collecte d'informations de dépendance pour le package 'SQLite.3.13.0' du projet 'FindDoublons', ciblant '.NETFramework,Version=v4.7.2'
La collecte des informations de dépendance a pris 2 ms
Tentative de résolution de dépendances pour le package 'SQLite.3.13.0' avec DependencyBehavior 'Lowest'
La résolution des informations de dépendance a pris 0 ms
Actions en cours de résolution pour installer le package 'SQLite.3.13.0'
Actions résolues pour installer le package 'SQLite.3.13.0'
Récupération du package 'SQLite 3.13.0' dans 'nuget.org'.
Ajout du package 'SQLite.3.13.0' au dossier 'C:\Users\berna\source\repos\FindDoublons\packages'
Package 'SQLite.3.13.0' ajouté au dossier 'C:\Users\berna\source\repos\FindDoublons\packages'
Package 'SQLite.3.13.0' ajouté à 'packages.config'
Installation réussie de « SQLite 3.13.0 » sur FindDoublons
L'exécution des actions de nuget a pris 665 ms
Temps écoulé : 00:00:00.9417323
PM> 

I use it in a VB.Net program using Visual Studio 2019 on Windows 11. But when I display References in Project Properties I don't see System.Data.Sqlite .Net assembly :

enter image description here

Is it normal System.Data.Sqlite is not displayed in References panel? What can I do to unlock my blocking situation?

CodePudding user response:

Download/install NuGet package enter image description here


Here's some sample code:

Imports System.Data.SQLite
Imports System.IO

Module HelperSQLite
    Private _connectionString As String = String.Empty
    Private _databaseFilename As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Test.sqlite")

    Sub New()
        'set value
        _connectionString = $"Data Source={_databaseFilename};Version=3;"
    End Sub

    Public Property DatabaseFilename As String
        Get
            Return _databaseFilename
        End Get
        Set(value As String)
            _databaseFilename = value
            _connectionString = $"Data Source={value};Version=3;"
        End Set
    End Property

    Public Sub CreateDatabaseAndTable()
        If Not File.Exists(DatabaseFilename) Then
            SQLiteConnection.CreateFile(DatabaseFilename)

            Dim sqlText As String = "CREATE TABLE Employee(
                                    ID INTEGER Constraint PK_Employee_ID PRIMARY KEY AUTOINCREMENT,
                                    FirstName TEXT,
                                    LastName TEXT
                                    );"

            Debug.WriteLine($"_connectionString (CreateDatabaseAndTable): '{_connectionString}'")

            Using con As SQLiteConnection = New SQLiteConnection(_connectionString)
                'open
                con.Open()
                Using cmd As SQLiteCommand = New SQLiteCommand(sqlText, con)
                    cmd.ExecuteNonQuery()
                End Using
            End Using
        End If
    End Sub

    Public Function GetData() As DataTable
        Dim dt As DataTable = New DataTable()
        Dim sqlText As String = "SELECT ID, FirstName, LastName FROM Employee;"

        Debug.WriteLine($"_connectionString (GetData): '{_connectionString}'")

        Using con As SQLiteConnection = New SQLiteConnection(_connectionString)
            'open
            con.Open()

            Using da As SQLiteDataAdapter = New SQLiteDataAdapter(sqlText, con)
                'get data
                da.Fill(dt)
                Return dt
            End Using
        End Using
    End Function

    Public Function GetDataAsString() As String
        Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()

        Dim dt As DataTable = GetData()

        For Each row As DataRow In dt.Rows
            sb.AppendLine($"ID: {row.Field(Of Int64)("ID")} FirstName: '{row.Field(Of String)("FirstName")}' LastName: '{row.Field(Of String)("LastName")}'")
        Next

        Return sb.ToString()
    End Function

    Public Function InsertData(firstName As String, lastName As String) As Integer
        Dim sqlText As String = "INSERT INTO Employee(FirstName, LastName) VALUES(@firstName, @lastName);"

        Debug.WriteLine($"_connectionString (InsertData): '{_connectionString}'")

        Using con As SQLiteConnection = New SQLiteConnection(_connectionString)
            'open
            con.Open()

            Using cmd As SQLiteCommand = New SQLiteCommand(sqlText, con)
                If Not String.IsNullOrEmpty(firstName) Then
                    cmd.Parameters.Add("@firstName", DbType.String).Value = firstName
                Else
                    cmd.Parameters.Add("@firstName", DbType.String).Value = DBNull.Value
                End If

                If Not String.IsNullOrEmpty(lastName) Then
                    cmd.Parameters.Add("@lastName", DbType.String).Value = lastName
                Else
                    cmd.Parameters.Add("@lastName", DbType.String).Value = DBNull.Value
                End If

                'execute
                Return cmd.ExecuteNonQuery()
            End Using
        End Using
    End Function
End Module

Usage - Create database and table:

CreateDatabaseAndTable()

Usage - Insert data:

InsertData("Bob", "Smith")
InsertData("John", "Doe")

Usage - Select:

Dim results As String = GetDataAsString()
Debug.WriteLine(results)

Resources:

  • Related