Showing posts with label unable. Show all posts
Showing posts with label unable. Show all posts

Tuesday, March 20, 2012

Retrieving image from database

Dear Friends,

I have read many solution over the net, but since I am unable to utilize anyone according to my needs I am seeking help from you people.

I have a table imagedata in sql server 2005 having fields name and imageperson. Name is string and imageperson is Image field. I have successfully stored name of the person and his image in database.

I have populated the dataset from codebehind and bind it to the repeater.

By writing <%#DataBinder.Eval(Container.DataItem,"name")%>

I am a able to retrieve the name of the person. But when I pass photodata as

<%#photogen((DataBinder.Eval(Container.DataItem,"imageperson")))%>

where photogen is function in code behind having structure

public void photogen(byte[] dataretrieved)

{

Response.BinaryWrite(datarerieved)

}

But it is giving error at <%#photogen((DataBinder.Eval(Container.DataItem,"imageperson")))%>

The best overloaded method match for '_Default.photogen(byte[])' has some invalid arguments

AND

Cannot convert object to byte[].

Can anyone please provide me working solution with code for aspx page and code behind.

Thanks and regards

Have a look at the sample projects at:

http://www.codeproject.com/aspnet/EasyThumbs.asp

Tuesday, February 21, 2012

Retrieve and display image inside an html file (stored in database) in binary format

Hi All,

I am not sure whether this is the right place to post this question. But I am unable to figure out what is the best solution to retrieve and display an image in a html file(stored in varbinary(max) column). I have a list of images in the file and I am supposed to display them. Can anybody please let me know what is the best way to do this?

Thanks a lot!!

HTML image links need to point to a URL. This means you can't just insert the image into the web form. If you have the images stored in a database, you will need to add another web page that will act like the image.

All you'll need in the new webpage is some code to get the image from the database as a byte array. Then write that out that image in the On_PageLoad as follows:

 
Dim img()As Byte' You'll need to add a function that will load the image into the byte array. It will pass in the id passed through the URL. img=LoadImage(Request.QueryString("id"))' Output the image and set the content type to jpeg Response.ContentType ="image/jpeg" Response.Expires = -1 Response.BinaryWrite(img) Response.End()

If the above was in a page called getImage.aspx you could link to it like this

<img src="http://pics.10026.com/?src=getImage.aspx?id=2" />

Hopefully that can get you pointed in the right direction. Let us know if you have any other questions.