streaming image in access



is there any way to store image in access database. I know there is an image
datatype in SQL.
I am trying to make use of a piece of code to stream an image and then store
it in access

System.Byte[] FileByteArray = new System.Byte[FileLength];
System.IO.Stream StreamObject = UpFile.InputStream;

Here I am converting it into stream and then using this piece of code to
insert into the database

System.String SqlCmd = "INSERT INTO Images (Image, ContentType,
ImageDescription, ByteSize) VALUES (?, ?, ?, ?)";
System.Data.OleDb.OleDbCommand OleDbCmdObj = new
System.Data.OleDb.OleDbCommand(SqlCmd, Con);
OleDbCmdObj.Parameters.Add("@Image", System.Data.OleDb.OleDbType.Binary,
FileLength).Value = FileByteArray;
System.Data.OleDb.OleDbType.VarChar,50).Value = UpFile.ContentType;
System.Data.OleDb.OleDbType.VarChar,100).Value = txtDescription.Text;
System.Data.OleDb.OleDbType.VarChar,100).Value = UpFile.ContentLength;

the Insert fails and I think it because of the first commandparameter.

Please advice,



Sylvain Lafontaine

First, there are many exemples on the web about inserting images in a
SQL-Server database. Why don't you try a little Google search?

Second, the image datatype in SQL is not really an image datatype but
instead a binary field of variable length. The fact that you can store an
image inside it won't mean that it will get displayed if the client used to
query the database cannot display an image from a binary field. An exemple
of such a client is Access. Access is able to display OLE Embedded and OLE
Linked Images but is not able to display simple images; those without an OLE

S. L.

Larry Linson

is there any way to store image in access
database ....

The sample imaging databases at illustrate three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach. Two of the
approaches do not use OLE Objects and, thus, avoid the database bloat, and
some other problems, associated with images in OLE Objects.

If you are printing the images in reports, to avoid memory leakage, you
should also see MVP Stephen Lebans' is an Access97 MDB containing a report that fails during
the Access formatting process prior to being spooled to the Printer Driver.
This MDB also contains code showing how to convert the contents of the Image
control to a Bitmap file prior to printing. This helps alleviate the "Out of
Memory" error that can popup when printing image intensive reports.

None of this is, of course, exactly what you want to do but the examples of
storing and retrieving images may help.

Larry Linson
Microsoft Access MVP




Access can certainly store raw-binary image data in the 'OLE Object' field type, similar to using Image
in SQL Server. I'm not sure whether it is possible to insert binary in this way, though. Does it work
if you drop the binary field from your code ?

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question