Display Image from MS Access

Nov 22 2004 1:51 AM
Hello, I am new here, and I have trouble displaying image from MS Access. I have already read the sample codes from http://www.c-sharpcorner.com/Code/2002/Feb/FlashCardsMG.asp but the sample program works with SQL Server not Access, and I tried to do the similar thing and here is some of my codes. private void Display( DataSet dataSet ) { try { // get first DataTable--there always will be one DataTable dataTable = dataSet.Tables[ 0 ]; if ( dataTable.Rows.Count != 0 ) { cardnoTextBox.Text = ( string ) dataTable.Rows[ 0 ][ 0 ]; field1TextBox.Text = ( string ) dataTable.Rows[ 0 ][ 1 ]; field2TextBox.Text = ( string ) dataTable.Rows[ 0 ][ 2 ]; byte[] MyData = null; MyData = ( byte[] )dataTable.Rows[ 0 ][ 3 ]; int ArraySize = new int(); ArraySize = MyData.GetUpperBound(0); FileStream fs = new FileStream("tmp.gif", FileMode.OpenOrCreate, FileAccess.Write); fs.Write(MyData, 0,ArraySize+1); // don't ask me why, but I had to add 1 here for this to work fs.Close(); pictureBox1.Image = new Bitmap("tmp.gif"); } else statusTextBox.Text += "\r\nNo record found\r\n"; } catch ( System.Data.OleDb.OleDbException oleException ) { Console.WriteLine( oleException.StackTrace ); statusTextBox.Text += oleException.ToString(); } } I already saved the image as OLE object in Access which the file type is .gif, but it still doesn't work. Also, I have this error: An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll Additional information: Invalid parameter used. which I have no idea what to do with it... Thank you all.

Answers (1)