How to Use VB With SQLite
As a programming language, Visual Basic has the capability to develop extremely robust and lightweight applications. One of the ways that VB applications can be kept as lightweight as possible and decrease overall CPU load is by using SQLite, a database infrastructure based on MySQL that is often used as a temporary file cache in desktop applications.
Instructions
-
-
1
Create a new VB project by clicking on "File" and then navigating to "New Visual Basic" and then "Windows from Application."
-
2
Create the SQLite database by creating a subroutine to generate the database itself:
Private Sub btn_createdb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_createdb.Click
'Save Dialog Box
Dim f As New SaveFileDialog
f.Filter = "SQLite 3 (*.db3)|*.db3|All Files|"
f.ShowDialog()
'Create Database
Dim SQLconnect As New SQLite.SQLiteConnection()
'Database Doesn't Exist so Created at Path
SQLconnect.ConnectionString = "Data Source=" & f.FileName & ";"
SQLconnect.Open()
SQLconnect.Close()
End Sub
-
-
3
Create the tables for the database and name the header row.
-
4
Put together the rest of the database's structure by executing the following VB routine:
Dim f As New OpenFileDialog
f.Filter = "SQLite 3 (*.db3)|*.db3|All Files|*.*"
If f.ShowDialog() = DialogResult.OK Then
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
SQLconnect.ConnectionString = "Data Source=" & f.FileName & ";"
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
'SQL query to Create Table
SQLcommand.CommandText = "CREATE TABLE foo(id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, description TEXT, image BLOB);"
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
End If
-
1