Question How to put OLEObject image from Access into PictureBox control

DaveRI

New member
Joined
Dec 23, 2011
Messages
2
Programming Experience
Beginner
Hello All,

I'm trying to pull an image stored as an OLEObject from an Access DB and load it into a PictureBox control using VB.NET. Based on where the exception is getting thrown, the code is making a connection to the database and the query is working. However, I am getting a System.ArgumentException message that tells me the "Parameter is not valid" on the following line:

newImage = Image.FromStream(imgMemoryStream)

Full Code:

Imports System.IO
Imports System.Data.OleDb


Public Class Form1


Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim imgByte() As Byte
Dim connString As String
Dim sqlCommand As String
Dim comm As OleDbCommand
Dim WorkingDirectory As String = Application.StartupPath
Dim newImage As Image
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "Photo.accdb; Persist Security Info=True"
Dim cnction As New OleDbConnection(connString)
cnction.Open()
sqlCommand = "SELECT imgData FROM Photo WHERE ID=1"
comm = New OleDbCommand(sqlCommand, cnction)
imgByte = comm.ExecuteScalar()
Dim imgMemoryStream As MemoryStream = New MemoryStream(imgByte)
newImage = Image.FromStream(imgMemoryStream)
PictureBox1.Image = newImage




End Sub
 

DaveRI

New member
Joined
Dec 23, 2011
Messages
2
Programming Experience
Beginner
Thanks for the reply. I saved the .jpg image using access. I'll try to create the save the image through VB and see if that makes any difference.
 
Top Bottom