Public Sub DownloadBlob(ByVal sqConnection As SQLiteConnection)
Dim sqCommand As New SQLiteCommand("SELECT * FROM Pictures", sqConnection)
sqConnection.Open()
Dim myReader As SQLiteDataReader = sqCommand.ExecuteReader(System.Data.CommandBehavior.Default)
Try
While myReader.Read()
Dim myBlob As SQLiteBlob = myReader.GetSQLiteBlob(myReader.GetOrdinal("Picture"))
If Not myBlob.IsNull Then
Dim FN As String = myReader.GetString(myReader.GetOrdinal("PicName"))
Dim fs As FileStream = New FileStream("D:\Tmp\" + FN + ".bmp", FileMode.Create)
Dim w As BinaryWriter = New BinaryWriter(fs)
w.Write(myBlob.Value)
w.Close()
fs.Close()
Console.WriteLine(String.Concat(FN, " downloaded."))
End If
End While
Finally
myReader.Close()
sqConnection.Close()
End Try
End Sub
Public Sub UploadBlob(ByVal sqConnection As SQLiteConnection)
Dim fs As FileStream = New FileStream("D:\Tmp\_Water.bmp", FileMode.Open, FileAccess.Read)
Dim r As BinaryReader = New BinaryReader(fs)
Dim myBlob As SQLiteBlob = New SQLiteBlob(r.ReadBytes(Convert.ToInt32(fs.Length)))
Dim sqCommand As SQLiteCommand = New SQLiteCommand("INSERT INTO Pictures (ID, PicName, Picture) VALUES(2,'Water',:Pictures)", sqConnection)
sqCommand.Parameters.Add("Pictures", myBlob)
sqConnection.Open()
Try
Console.WriteLine(String.Concat(sqCommand.ExecuteNonQuery(), " rows affected."))
Finally
sqConnection.Close()
r.Close()
End Try
End Sub