Load image from database BLOB?

L

Lauchlan M

I have a .jpg image in a BLOB field in my database and I want to load it
into a System.Web.UI.WebControls.Image image control.

I have some code like this that fills a datareader:

<<
NxDataReader dtrData;
nxCommand.Parameters["SessionID"].Value =
Request.QueryString["SessionDataID"];

nxConnection.Open();
dtrData = (NexusDB.ADOProvider.NxDataReader)nxCommand.ExecuteReader();

if (dtrData.Read())
{


// load imgECGImage from the BLOB

byte[] ECGBLOB = new byte[0];
ECGBLOB = (byte[])dtrData["ECG_Image"];
//int ArraySize = new int();
//ArraySize = ECGBLOB.GetUpperBound(0);

I now need to get the BLOB from the byte array into the imgECGImage image
web control.

Any pointers on how to do this? Or do I have to use a dataadapter and
dataset and databind that image field to that image component?

Thanks!

Lauchlan M
 
L

Lauchlan M

OK, I've now realised that an image control is not meant to work this way,
it's meant to work more like ina normal html page and point to an image url.

So do I have to store the image somewhere on the server, and given the file
path to it, work out the url for this path, and use this in the ImageURL
property of the image control? So in general I'd have some set of images
stored in some image folder and I'd have some naming convention to make sure
the image required for eachdifferent dynamically generated page is named
differently in this image folder.

Thanks!

Lauchlan M
I have a .jpg image in a BLOB field in my database and I want to load it
into a System.Web.UI.WebControls.Image image control.

I have some code like this that fills a datareader:

<<
NxDataReader dtrData;
nxCommand.Parameters["SessionID"].Value =
Request.QueryString["SessionDataID"];

nxConnection.Open();
dtrData = (NexusDB.ADOProvider.NxDataReader)nxCommand.ExecuteReader();

if (dtrData.Read())
{


// load imgECGImage from the BLOB

byte[] ECGBLOB = new byte[0];
ECGBLOB = (byte[])dtrData["ECG_Image"];
//int ArraySize = new int();
//ArraySize = ECGBLOB.GetUpperBound(0);

I now need to get the BLOB from the byte array into the imgECGImage image
web control.

Any pointers on how to do this? Or do I have to use a dataadapter and
dataset and databind that image field to that image component?
 
S

Steve C. Orr [MVP, MCSD]

You'll likely want a page that has the sole purpose of returning images.
Then you reference the address of that page from your Image control.

Here's further information pulling the data from your database and
outputting the file:
http://www.aspnetpro.com/features/2003/07/asp200307so_f/asp200307so_f.asp

Otherwise you may want store your files in a private folder and use
Response.Writefile once you've determined the user is authorized:
http://msdn.microsoft.com/library/d...fsystemwebhttpresponseclasswritefiletopic.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Lauchlan M said:
I have a .jpg image in a BLOB field in my database and I want to load it
into a System.Web.UI.WebControls.Image image control.

I have some code like this that fills a datareader:

<<
NxDataReader dtrData;
nxCommand.Parameters["SessionID"].Value =
Request.QueryString["SessionDataID"];

nxConnection.Open();
dtrData = (NexusDB.ADOProvider.NxDataReader)nxCommand.ExecuteReader();

if (dtrData.Read())
{


// load imgECGImage from the BLOB

byte[] ECGBLOB = new byte[0];
ECGBLOB = (byte[])dtrData["ECG_Image"];
//int ArraySize = new int();
//ArraySize = ECGBLOB.GetUpperBound(0);

I now need to get the BLOB from the byte array into the imgECGImage image
web control.

Any pointers on how to do this? Or do I have to use a dataadapter and
dataset and databind that image field to that image component?

Thanks!

Lauchlan M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top