By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,330 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,330 IT Pros & Developers. It's quick & easy.

Displaying images from a database

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.