Re: Storing/Retrieving BLOB Data directly into a PictureBox in VB.NET
Posted by: Patrick Gray
Date: December 05, 2007 09:22AM

This is what I came up with to display pictures from a memorystream
bypasses writing to a file. This is 2008 express.

Private Sub GetPicture()
'This retrieves the pictures from a mysql DB and buffers the rawdata into a memorystream
PictureBox1.ImageLocation = ""
Dim FileSize As UInt32
Dim rawData() As Byte

Dim conn As New MySqlConnection
Dim myNewStudentCommand As New MySqlCommand
Dim SQLGetPicture As String
Dim myData As MySqlDataReader

conn.ConnectionString = clsGlobal.connector

SQLGetPicture = "SELECT * FROM pictures WHERE id = ?autoid"

conn.ConnectionString = clsGlobal.connector


myNewStudentCommand.Parameters.AddWithValue("?autoid", tb_Stuid.Text)

myNewStudentCommand.Connection = conn
myNewStudentCommand.CommandText = SQLGetPicture

myData = myNewStudentCommand.ExecuteReader

'data is in memory

FileSize = myData.GetUInt32(myData.GetOrdinal("filesize"))
rawData = New Byte(FileSize) {}

'get the bytes and filesize

myData.GetBytes(myData.GetOrdinal("file"), 0, rawData, 0, FileSize)

Dim ad As New MemoryStream(100000)
Dim bm As Bitmap

ad.Write(rawData, 0, FileSize)
bm = New Bitmap(ad)



PictureBox1.Image = bm



End Try

End Sub

Options: ReplyQuote

Written By
Re: Storing/Retrieving BLOB Data directly into a PictureBox in VB.NET
December 05, 2007 09:22AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.