0
Reply

Accessing Image from MS Access and Displaying them in Windows Form

Shaurya Rastogi

Shaurya Rastogi

Jan 12 2007 5:41 AM
1.5k

1>I have to retrive and display images that are present in a MS Access Database.

2>The images have been  inserted in the database by the user by using the Insert Object Functionality of MS Access so the Image is displayed as Bitmap Image for .BMP and Package for .JPEG in the DataBase Image Field.

3>I have tried reading the data in a Byte Array and then display it but it dosent work that way.

//Obtain Image in a byte array
byImageArray  = (byte[])Command.ExecuteScalar();

//Read the byte array to memory stream
MemoryStream memStream = new MemoryStream(byImageArray);

//Read Image from the memory stream into picture box.
picImage.Image=Image.FromStream(memStream);

An exception is thrown is Argument Exception:Parameter is not valid.

This code works fine if we store image in DataBase Programmitically by using Byte Array,but not when we access a image that had been directly in the table by user by using Insert Object Functionality of MS Access