473,398 Members | 2,343 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,398 software developers and data experts.

Retreive images stored in Access database

Hi All,

How to retrieve images stored in Access database.
I am storing images(jpeg) as OleObject.
I want display them on my web page.
I am unable to do so.Please help me I am using C#
The code is as

// Put user code to initialize the page here
int ImgID = System.Convert.ToInt32(Request.QueryString["ImgID"]);
System.Data.OleDb.OleDbConnection Con = new
System.Data.OleDb.OleDbConnection(@"Provider=Micro soft.Jet.OLEDB.4.0;Data
Source=C:\images.mdb;");
System.String SqlCmd = "SELECT Image FROM Images";
System.Data.OleDb.OleDbCommand OleDbCmdObj = new
System.Data.OleDb.OleDbCommand(SqlCmd, Con);
Con.Open();
System.Data.OleDb.OleDbDataReader OleReader =
OleDbCmdObj.ExecuteReader();
while(OleReader.Read())
{
Response.ContentType = "IMAGE/JPEG";

Response.BinaryWrite( (byte[])OleReader["Image"]);
}

Response.End();

Tahnks,
Anitha

Nov 24 '05 #1
2 1564
Hi Anitha,

you'll have to use a custom HTTP Handler for this (or use a separate
dedicated ASPX, easier but less nice). In your code I notice you are
using a while loop to read images. Don't forget you can only serve 1
image, as the client is only requesting a single image
(http://mysite/myimage.jpg).

namespace SharpCMS.Core.HttpHandlers
{
using System;
using System.Web;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
using SharpCMS.Schema;
using SharpCMS.Core.Utils;

public class ResourceHandler
: IHttpHandler
{
public bool IsReusable
{
get { return false; }
}

public void ProcessRequest(HttpContext context)
{
string resourceID = context.Request.QueryString["resID"];
Guid guid = new Guid(resourceID);
if (guid != Guid.Empty)
{
FileResource resource = ResourceManager.GetFileResource(new
Guid(resourceID));
context.Response.ContentType = resource.MimeType;
using (BinaryWriter writer = new
BinaryWriter(context.Response.OutputStream))
{
writer.Write(ResourceManager.GetFileBytes(resource .ID));
}
}
context.Response.End();
}
}
}

This code is taken from my CMS'ish application, SharpCMS. The call to
ResourceManager.GetFileBytes does nothing more than your select. I use
Sql Server and an column of type Image. The SqlCommand returns a byte[]
for this.

Hope it helps,

Grtz, Wouter
Trainer - Info Support - www.infosupport.com
www.dive-in-it.nl

Nov 24 '05 #2
B
Hey Wouter,

Do you have the same code in VB.NET ?
I would like to retreive my images as well from SQL 2005 Express DB.

Thanks,
Bart

"Wouter van Vugt" wrote:
Hi Anitha,

you'll have to use a custom HTTP Handler for this (or use a separate
dedicated ASPX, easier but less nice). In your code I notice you are
using a while loop to read images. Don't forget you can only serve 1
image, as the client is only requesting a single image
(http://mysite/myimage.jpg).

namespace SharpCMS.Core.HttpHandlers
{
using System;
using System.Web;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
using SharpCMS.Schema;
using SharpCMS.Core.Utils;

public class ResourceHandler
: IHttpHandler
{
public bool IsReusable
{
get { return false; }
}

public void ProcessRequest(HttpContext context)
{
string resourceID = context.Request.QueryString["resID"];
Guid guid = new Guid(resourceID);
if (guid != Guid.Empty)
{
FileResource resource = ResourceManager.GetFileResource(new
Guid(resourceID));
context.Response.ContentType = resource.MimeType;
using (BinaryWriter writer = new
BinaryWriter(context.Response.OutputStream))
{
writer.Write(ResourceManager.GetFileBytes(resource .ID));
}
}
context.Response.End();
}
}
}

This code is taken from my CMS'ish application, SharpCMS. The call to
ResourceManager.GetFileBytes does nothing more than your select. I use
Sql Server and an column of type Image. The SqlCommand returns a byte[]
for this.

Hope it helps,

Grtz, Wouter
Trainer - Info Support - www.infosupport.com
www.dive-in-it.nl

Dec 23 '05 #3

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

Similar topics

0
by: Lee | last post by:
Hello, This is a genral enquiry before I send out a more detailed request. I am unable to retreive image files from a mysql database using IE 5.2 on the mac OS X platform. I have built a...
4
by: RichG | last post by:
I have an Access database/forms application that has images stored in it. I need to develop a new VB that utilizes Oracle or the file system as the underlying storage for these images. In order...
4
by: Dom Hicklin | last post by:
I have created a form onto which images can be dropped and thus added to the OLE field of a Table (Access 2000 linked to SQL 2000 server). I use the Stephen Lebans ExportOLE function to do this...
0
by: Frank S. Romano | last post by:
Hello, Does anyone know how to bind the image property of a picture control to an Access 2000 database OLE object column that contains a MS Photo Editor 3.0 photo? When I try binding the picture...
10
by: Neo Geshel | last post by:
I am seeking to hand-roll my own blog in ASP.NET 2.0 and SQLExpress 2005. Why? Because I can. Because I will gain experience. The one thing that has me stumped at square one is inline images....
3
by: leen85 | last post by:
helo everybody...i'm lina...i need your help...i have a problem in Access...i have 38000 images for my company employee which size about 5GB to stored in database...as we know we cant stored too...
0
by: leen85 | last post by:
helo everybody...i'm lina...i need your help...i have a problem in VB and Access...i have 38000 images for my company employee which size about 5GB to stored in database...as we know we cant stored...
0
by: Mahil | last post by:
I have trying to read the sample database fiields in the Northwind from MS Access into an Applet. I am able to successully read and display all the text fields. But the difficulty comes with 'Photo"...
6
n8kindt
by: n8kindt | last post by:
i have linked a mySQL database (that populates data in our webstore) with my Access 2007 database. i want to be able to see the images in access also. however, i only have a referring url to work...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.