This should answer any questions you have about the basics of VB.net and SQLite.
Insert/Update/Delete Values:
Dim f As New OpenFileDialog
f.ShowDialog()
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
SQLconnect.ConnectionString = "Data Source=" & f.FileName & ";"
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
SQLcommand.CommandText = "INSERT INTO Item (type) VALUES ('something')"
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
Read Values:
Dim f As New OpenFileDialog
f.ShowDialog()
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
SQLconnect.ConnectionString = "Data Source=" & f.FileName & ";"
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
SQLcommand.CommandText = "SELECT * FROM Item"
Dim SQLreader As SQLiteDataReader = SQLcommand.ExecuteReader()
While SQLreader.Read()
TextBox1.Text &= String.Format("ID = {0}, MYVALUE = {1}", SQLreader(0), SQLreader(1)) & vbCrLf
End While
SQLcommand.Dispose()
SQLconnect.Close()
Convert BlobToImage (with how to use it):
Private Function BlobToImage(ByVal blob)
Dim mStream As New System.IO.MemoryStream
Dim pData() As Byte = DirectCast(blob, Byte())
mStream.Write(pData, 0, Convert.ToInt32(pData.Length))
Dim bm As Bitmap = New Bitmap(mStream, False)
mStream.Dispose()
Return bm
End Function
Dim f As New OpenFileDialog
f.ShowDialog()
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
SQLconnect.ConnectionString = "Data Source=" & f.FileName & ";"
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
SQLcommand.CommandText = "SELECT * FROM item WHERE id = 1"
Dim SQLreader As SQLiteDataReader = SQLcommand.ExecuteReader()
While SQLreader.Read()
'Where 1 is the Second Column in the Table
PictureBox1.Image = BlobToImage(SQLreader(1))
End While
SQLcommand.Dispose()
SQLconnect.Close()
Convert ImageToBlog (with how to use it):
Public Function ImageToBlob(ByVal filePath As String) As Byte()
Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
Dim bm() As Byte = br.ReadBytes(fs.Length)
br.Close()
fs.Close()
Return bm
End Function
Dim f As New OpenFileDialog
f.ShowDialog()
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
SQLconnect.ConnectionString = "Data Source=" & f.FileName & ";"
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
SQLcommand.CommandText = "INSERT INTO TileSet_" & TextBox1.Text & " (id,image) VALUES('1',@image)"
Dim photo() As Byte = ImageToBlob("C:\img.png")
Dim SQLparm As New SQLiteParameter("@image", photo)
SQLparm.DbType = DbType.Binary
SQLparm.Value = photo
SQLcommand.Parameters.Add(sqlpar)
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
Put Names of Tables in a LIST:
Dim f As New OpenFileDialog
f.ShowDialog()
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
SQLconnect.ConnectionString = "Data Source=" & f.FileName & ";"
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
Dim SchemaTable = SQLconnect.GetSchema(SQLiteMetaDataCollectionNames.Tables)
For int As Integer = 0 To SchemaTable.Rows.Count - 1
If SchemaTable.Rows(int)!TABLE_TYPE.ToString = "table" Then
ListBox1.Items.Add(SchemaTable.Rows(int)!TABLE_NAME.ToString())
End If
Next
SQLcommand.Dispose()
SQLconnect.Close()
I'm gonna keep editing this.