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 vb.net 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

conn.Open()

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

myNewStudentCommand.Connection = conn
myNewStudentCommand.CommandText = SQLGetPicture
Try

myData = myNewStudentCommand.ExecuteReader
myData.Read()

'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)

myData.Close()


conn.Close()
conn.Dispose()

PictureBox1.Image = bm

ad.Dispose()

Catch

End Try


End Sub

Options: ReplyQuote


Subject
Written By
Posted
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.