We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 68,261 times

Contents

Related Categories

Retrieving Images from a Database - Introduction

dave123aspx

Introduction

In the first part of our article, we uploaded a file and stored it in our database. Now, we are going to stream binary data out of a database and to a browser client.

Refresher - Table Structure

Lets quickly refresh ourselves with the table structure we are using for storing images.

CREATE TABLE [dbo].[image] (
  [img_pk] [int] IDENTITY (1, 1) NOT NULL ,
  [img_name] [varchar] (50) NULL ,
  [img_data] [image] NULL ,
  [img_contenttype] [varchar] (50) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[image] WITH NOCHECK ADD
CONSTRAINT [PK_image] PRIMARY KEY NONCLUSTERED
(
  [img_pk]
) ON [PRIMARY]
GO

We have 4 columns in our sql server:

img_pk - our Identity primary key.
img_name - the friendly name we are using for our image
img_data - the binary data field we are storing our image in.
img_contenttype - the Mime type of our image, for example: image/gif

Comments

  • Re: can't get this to work

    Posted by manoj3939 on 18 Apr 2007

    I am Facing the sam e problem, i am able to store an image into a database as image type but fetching from database in displaying it on a web page is not working.


    Fetching from the da...

  • Posted by tomk10 on 14 Dec 2005

    Whar is Bind? I've only seen DataBinder.Eval used here and your examp,le causes a Compilation Error.

  • can't get this to work

    Posted by Jud101 on 25 Nov 2005

    I've been struggling to get an image to view on my webpage. I had to make a few changes but no way would it work for me. I ended up coping and pasting everything, ran into the error at this point : ...

  • Fix

    Posted by Louie88 on 15 Nov 2005

    Hi there! Try this „quite” simple fix. Thanks Dave, you helped a lot with this images mystery…

    ...

  • Same Problem

    Posted by tadhg88 on 22 Feb 2005

    hey guys i have the exact same problem as ye have and im just wondering if ye managed to find a solution
    thanks in advance
    tadhg88