GoGreen PC Tune-Up™
Learn More

Insta-Install™
this is how ssl encrypt our websites
MTNCOMP | List View | Table View | myBlog (1775 Entries)
myBlog Home

Blog


Accessing SQLite databases and Windows Visual Studio VB.Net or C# programming

Microsoft Windows SQL

by Mountain Computers Inc., Publication Date: Monday, October 5, 2020

View Count: 3105, Keywords: SQLite, VS 2019, Windows, English Dictionary, Hashtags: #SQLite #VS2019 #Windows #EnglishDictionary



[Code is below] -- I had the hardest time finding in the programming documentation and references something that I could use to access a SQLite v3 database (english dictionary from github) from Microsoft Visual Studio VB.Net, C#, C++ (any language I am happy to leverage).
 
This project I am working on is going to just access a local SQLite database v3 that holds an open source English dictionary from Github, and read from it using some form of programming language that is both high nor low.
 
Well, I figured it out over the weekend. After all the partial examples that did not have fully functional examples, here is my example. It works. I'll explain probably in a video. This will help beginners and intermediate programmers trying to get access to a local SQLite database.
 
Ps. It took me 7 hours to figure it out from start to finish. All the references I looked at and tried failed miserably. There was not a complete beginning to end solution. 
 
[Update 10/09/2020] I got sidetracked with work
 
here is the video:
 
YouTube Channel GGPCTU :  https://youtu.be/Ds7wFtYQn3s
 
'Nuget Dependency library is System.Data.SQLite.Core and along comes Entity.Framework, System.Data.SQLite, System.Data.SQLite.EF6, and System.Data.SQLite.Linq
 
--------------------------
here is the code:
 
Imports System.Data.SQLite
Public Class Form1
    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Application.Exit()
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call mySQLiteReadDB()
    End Sub
    Private Function MyDictionaryExists()
        MyDictionaryExists = False
        If My.Computer.FileSystem.FileExists("en-dictionary.db") Then
            MyStatusLine.Text = "Dictionary db file exists."
            Debug.Print("Dictionary db file exists.")
            ListBox1.Items.Add("Dictionary db file exists.")
            MyDictionaryExists = True
        Else
            MyStatusLine.Text = "Dictionary db file does not exist."
            Debug.Print("Dictionary db file does not exist.")
            ListBox1.Items.Add("Dictionary db file does not exist.")
        End If
    End Function

    Private Sub mySQLiteReadDB()
        Try
            If MyDictionaryExists() Then
                Dim myconnectionString = "Data Source=" & Application.StartupPath & "\en-dictionary.db" & ";Version=3; FailIfMissing=True;"
                Dim myConnection As SQLiteConnection = New SQLiteConnection()
                Dim myCommand As New SQLite.SQLiteCommand()
                Dim myData As SQLite.SQLiteDataReader

                myConnection.ConnectionString = myconnectionString
                myConnection.Open()
                ' execute queries, etc

                myCommand = myConnection.CreateCommand
                myCommand.CommandText = "SELECT * FROM englishdictionary LIMIT 15"
                myData = myCommand.ExecuteReader()
                myData.Read()
                If myData.HasRows Then
                    ListBox1.Items.Add("Has rows. Reading 15 records.")
                    Dim mycount
                    mycount = 1
                    Do While (myData.Read())
                        ListBox1.Items.Add(mycount & ") " & myData(0) & "," & myData(1) & ", " & myData(2))
                        Debug.Print(mycount & ") " & myData(0) & ", " & myData(1) & ", " & myData(2))
                        mycount = mycount + 1
                    Loop
                End If
                myConnection.Close()
            End If

        Catch
            'nothing here to do
        Finally
            'nothing here to do
        End Try

    End Sub
End Class
 
 
 
more to come...

if you found this article helpful, consider contributing $10, 20 an Andrew Jackson or so..to the author. more authors coming soon
FYI we use paypal or patreon, patreon has 3x the transaction fees, so we don't, not yet.

© 2024 myBlog™ v1.1 All rights reserved. We count views as reads, so let's not over think it.