Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Display an image from access database

Reply
Thread Tools

Display an image from access database

 
 
=?Utf-8?B?RXJpYyBLZXVuZw==?=
Guest
Posts: n/a
 
      05-14-2004
Hi all,

my case is I want to get an image from access database and I just know it's "OLE object" field type at access
I also don't know how to insert it into access

here is my code and it just can display a invalid image

try
dim strConn as string
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath
("ERIC_TEST_V05.mdb") & "; Jet OLEDBatabase Password=123456;"

Dim objConn as New OleDBConnection(strConn)
objConn.Open()

Dim objCmd as New OleDbCommand()
objCmd.Connection = objConn
objCmd.CommandText = "SELECT logo FROM office_profile"

Dim objReader as OleDbDataReader
objReader = objCmd.ExecuteReader

While objReader.Read
'Response.BinaryWrite(objReader("logo") & "<br>")

Dim bindata() As Byte = objReader.GetValue(0)

Response.Clear()
Response.ContentType = "Image/bmp"
Response.BinaryWrite ( bindata )

End While

objConn.close()
catch ex as exception
response.write (ex.tostring())
end try

Please help .

Regards,
Eric Keung
 
Reply With Quote
 
 
 
 
Jason DeFontes
Guest
Posts: n/a
 
      05-14-2004
The problem is, when you insert an image into an Access database using
Insert/Object from the Access menu, it doesn't just store the raw binary
data of the file. It stores it as an OLE object which contains that data
and has some kind of wrapper that's able to activate the OLE object so
you can view/edit it from within and Access form.

Cool for Access, but not good if you're trying to display it on the web.
If you just stream out the data of the OLE object like you're doing,
it's not in the format that a browser can recognize as valid image data.

The only way to get this to work is to programatically insert the data
into Access, so you can write only the raw image data and not the OLE
wrapper. Then when you pull the data out and stream it to the browser it
will be in a format that the browser can display.

I've done this before, but I can't find the code that I used. Here's an
article that might be helpful though:

http://www.stardeveloper.com/article...3031201&page=1

-Jason

Eric Keung wrote:

> Hi all,
>
> my case is I want to get an image from access database and I just know it's "OLE object" field type at access
> I also don't know how to insert it into access
>
> here is my code and it just can display a invalid image
>
> try
> dim strConn as string
> strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath
> ("ERIC_TEST_V05.mdb") & "; Jet OLEDBatabase Password=123456;"
>
> Dim objConn as New OleDBConnection(strConn)
> objConn.Open()
>
> Dim objCmd as New OleDbCommand()
> objCmd.Connection = objConn
> objCmd.CommandText = "SELECT logo FROM office_profile"
>
> Dim objReader as OleDbDataReader
> objReader = objCmd.ExecuteReader
>
> While objReader.Read
> 'Response.BinaryWrite(objReader("logo") & "<br>")
>
> Dim bindata() As Byte = objReader.GetValue(0)
>
> Response.Clear()
> Response.ContentType = "Image/bmp"
> Response.BinaryWrite ( bindata )
>
> End While
>
> objConn.close()
> catch ex as exception
> response.write (ex.tostring())
> end try
>
> Please help .
>
> Regards,
> Eric Keung

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Display Image from Database in Image Control chrispragash@hotmail.com ASP .Net 1 10-18-2006 01:48 PM
Display Image from Database in an Image control chrispragash@hotmail.com ASP .Net Web Services 1 08-25-2005 07:38 PM
How to display an image from a OLE Object field of an Access database ? Sandi ASP .Net 3 11-06-2003 12:52 PM



Advertisments