Public Sub DownloadBlob(ByVal myConnection As MySqlConnection)
Dim myCommand As New MySqlCommand("SELECT * FROM Test.Pictures", myConnection)
myConnection.Open()
Dim myReader As MySqlDataReader = myCommand.ExecuteReader(System.Data.CommandBehavior.Default)
Try
While myReader.Read()
Dim myBlob As MySqlBlob = myReader.GetMySqlBlob(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()
myConnection.Close()
End Try
End Sub
Public Sub UploadBlob(ByVal myConnection As MySqlConnection)
Dim fs As FileStream = New FileStream("D:\Tmp\_Water.bmp", FileMode.Open, FileAccess.Read)
Dim r As BinaryReader = New BinaryReader(fs)
Dim myBlob As MySqlBlob = New MySqlBlob(r.ReadBytes(Convert.ToInt32(fs.Length)))
Dim myCommand As MySqlCommand = New MySqlCommand("INSERT INTO Test.Pictures (ID, PicName, Picture) VALUES(2,'Water',:Pictures)", myConnection)
myCommand.Parameters.Add("Pictures", myBlob)
myConnection.Open()
Try
Console.WriteLine(String.Concat(myCommand.ExecuteNonQuery(), " rows affected."))
Finally
myConnection.Close()
r.Close()
End Try
End Sub