questions about Image stored in DB

  • Thread starter Thread starter Edward
  • Start date Start date
E

Edward

Hi,

I've one employee table, with one column as Image type. So I want to
display all the information in one form, where I choose an ImageButton to
display the column .

I found nearly all the suggestion is using ImageButton.ImageUrl =
"imagereader.aspx?id=n" , that means I should create another .net page, and
as you all know, imagereader.aspx should read the column again from DB,

you must have got my question , how can I retrieve only once from DB,
then display the Image column and other text fields in one form.

maybe the answer will be very easy, but to me, it's now the question.

Looking forward to the answer from you. Thanks.
 
Hi,

Image tag has src attribute that you need to set. Src attribute should
be point to image on your serve. Its browser duty to download image bits
from the given address, maintain cache for that image and render it on
the screen.

So, instead of creating images (files) while you get rows from DB and
set those images to src address its better practice to split the job and
to bypass the need to write IO files. this is the reason why your page
just get alpha numeric data and set the image src to other "page" with
query string holding data necessary to retrieve image from DB. this
"page" read just image bytes and by changing response mime send image
bytes to browser, without saving files on server.

I wrote "page" because for situations like that, where the page
"services" (postback, controls, etc.) are unnecessary you should use
Ihttphandler which will be faster then ASP.NET page processing.

HTH

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Dear Edward

I hope you are using a Datagrid or other stuff to display the information.

Anyway, if you are using a DataReader to read the records, then you can store the Image URL in the database and retrieve it

then you can give as ImageButton.ImageUrl = objrdr["ImageURL"]

that will help you in displaying the images from the database

if you are displaying a number of Images, then you can use the above within the while(Reader.Read) so that it displays the respective images

hope it helps

----- Edward wrote: ----

Hi

I've one employee table, with one column as Image type. So I want t
display all the information in one form, where I choose an ImageButton t
display the column

I found nearly all the suggestion is using ImageButton.ImageUrl
"imagereader.aspx?id=n" , that means I should create another .net page, an
as you all know, imagereader.aspx should read the column again from DB

you must have got my question , how can I retrieve only once from DB
then display the Image column and other text fields in one form

maybe the answer will be very easy, but to me, it's now the question

Looking forward to the answer from you. Thanks
 
You can use this

byte[] btdata = null;
object oImage;
sqlComm.CommandText="pub your select sql statement here";
myReader= sqlComm.ExecuteReader();

if (myReader.Read())
{
oImage=myReader["your image column"];
if(oImage.Equals(System.DBNull.Value))
//imgImage is webcontrol.image
imgImage.ImageUrl="no image file path";
else
{
btdata = (byte[]) oImage;
int arraysize = btdata.GetUpperBound(0);
Stream st = new MemoryStream(btdata,0,arraysize);
Bitmap bm = new Bitmap(st);
bm.Save("temp file that you will create for storing the picture");
st.Close();
imgImage.ImageUrl = s1;
}
}

Regards
Martin Marinov
 
I think that i miss something,

what I meant is way to let your user to wait for page, that will take
more time to display with images. if you split the images from data,
users can see data faster and Images are loading while data already
displayed.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Back
Top