Retrieving Image OLE Object from Access Database

Sep 17 2008 4:49 PM

Hi

I have an access database that has a column in a table that has bmp images stored as ole object type. I have a c# windows form with a picturebox control. I need to be able to retrieve an image from the database but i do not know how. The event is triggered by a button. The database contains film titles and their cover images. The data is loaded into a dataset and then i use sql statements in the table adapters to return the desired row from the table, Here is the code so far,

 

string selGenre = cbGenre.SelectedItem.ToString();

if (selGenre == "All")

{

int iMin = 1;

int iMax = filmsDataSet.Films.Rows.Count;

int iRand = RandomFilm(iMin, iMax);

txtFilm.Text = filmsTableAdapter.FillByFilm(iRand).ToString();

byte[] byImage = new byte[0];

byImage = (byte[])(filmsTableAdapter.ImageFromID(iRand));

MemoryStream stmImage = new MemoryStream(byImage);

pictureBox1.Image = Image.FromStream(stmImage);

}

But i get an exception withe the line - byImage = (byte[])(filmsTableAdapter.ImageFromID(iRand));

 

Any help would be much appreciated.

 

Thanks


Answers (2)