FileToBLOB
Previous Top Next

Loads the data of the specified file and converts it to BLOB type before saving it in a database.
Syntax: FileToBLOB (File As String) As String

Example:
'con is a Connection object, cmd is a Command object and reader is a DataReader object.
Sub Globals

End Sub

Sub App_Start
      Form1.Show
      con.New1
      reader.New1
      con.Open("Data Source = " & AppPath & "\1.db3") 'Opens the database.
      cmd.New1("CREATE TABLE IF NOT EXISTS pictures (name TEXT, image BLOB)",con.Value)
      cmd.ExecuteNonQuery
      
      'Save the image in the database (change the image name to an existing image file).
      cmd.CommandText = "INSERT INTO pictures values('smiley.gif'," & cmd.FileToBLOB(AppPath & "\smiley.gif") & ")"
      cmd.ExecuteNonQuery
      
      'Load the image from the database.
      cmd.CommandText = "SELECT image FROM pictures"
      reader.Value = cmd.ExecuteReader
      reader.ReadNextRow
      Form1.Image = reader.GetImage(0)
End Sub