473,325 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Displaying images from a database

Hi

I have a form and need to display an image that is returned along with other
data, i.e. Member Data, from a database row.
How do I display this image in my webform?

S
Nov 13 '05 #1
2 3936
Hi Sam,

You need to load the image from the DB, create a file accesible from the
IIS server and then set the ImageUrl property of the image to this new file,
here is the code I'm using:

//First load the image fromt he DB:
SqlCommand cmd = new SqlCommand();

cmd.CommandText = "LoadDocument";

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@dID", SqlDbType.Int).Value = id;

SqlDataReader reader = DataProvider.ExecuteReader( cmd);

//Now save the file, see that I use a Guid for name the file, as I put all
the files in the same folder it can be possible that two images had the same
name originally.

//This line is to keep a reference of the new name, NOTE that as I use
different kind of files ( not only images) I have to keep the extension of
the file

name = Guid.NewGuid().ToString() + "." + origname.Substring(
origname.LastIndexOf(".")+1);

//Physicalname has the path where the file will be saved

physicalname = physicalname + @"\" + name;

FileStream file = new FileStream( physicalname, FileMode.Create);

file.Write( (byte[])reader["Data"], 0,
((byte[])reader["Data"]).GetUpperBound(0)+1 );

file.Close();

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"SamIAm" <sa****@rubbachicken.com> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
Hi

I have a form and need to display an image that is returned along with other data, i.e. Member Data, from a database row.
How do I display this image in my webform?

S

Nov 13 '05 #2
How is it stored? Byte array? "Text" type? Base64 Encoded string?

"SamIAm" <sa****@rubbachicken.com> wrote in message news:<uZ**************@TK2MSFTNGP12.phx.gbl>...
Hi

I have a form and need to display an image that is returned along with other
data, i.e. Member Data, from a database row.
How do I display this image in my webform?

S

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Vinay | last post by:
Hi All: I have a small application that stores images either in the database or as files (depending on the user preference). I'm in the process of providing a web interface to this application....
3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
2
by: marvin | last post by:
Hi, I am trying to display images in a repeater from a SQL database and do some transformations on the image prior to displaying them (such as thumbnail with a shadow). The problem is I can't...
3
by: CLEAR-RCIC | last post by:
I have several images i want to display in an ASP.Net application. The images are being passed to me in binary format from another application. Is there a good way to write them directly to an...
8
by: Lloyd Sheen | last post by:
I have a list of JPG's which are found in a SQL Server database. When the page selects a certain piece of data it will refer to the file system (resident on IIS server with a virtual directory)...
10
by: gnewsgroup | last post by:
I've googled and tried various approaches, but could not resolve this problem. The article at MSDN: Displaying Images in a GridView Column only presents a simple case where all data (including the...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
14
by: ashraf02 | last post by:
i used a code from a website that allows you to display images. however everything works fine from storing the image to the database but it does not display the image. the following code is the...
5
by: asharda | last post by:
Hi, I have an ASP.Net application with the back-end as VB.Net. I have a combo control and on the selection changed event of the combo control I need to get the selected image from the database...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.