Storing And Displaying Image From Database

Aug 17, 2007

1 min read

.NET2.0

SQL-Server-2005

VS2005

C#2.0

C#

ASP.NET

SQL

Windows

.NET

SQL-Server

Visual-Studio

DBA

Dev

ADO.NET

WebForms

Intermediate

Author picture

by N a r e s h P a t e l

Contributor

29k Views

Introduction

Actually it is not good to store Image file into Database But some time it is necessary to store it. Here I am giving solution to storing and displaying Image to Database.

Using the code

This will help you to storing and Displaying Image to Database -here Sql Server 2005.

First of all create page named AddEmployee.aspx and add repeater to it shown in source file.

The main idea is that: I am storing Image files into database directly into Binary Format. So storing it first convert it into Binary:

CS
            SqlParameter prmFName = 

Now at Image viewing time:

CS
      <td id=

At the DisplayImage.aspx Page:

CS
            cmdAddEmp.CommandText = 

Response.BinaryWrite(byteImg) writes binary content of the Image and display Image.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)