.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Retreiving image from database

Posted By:      Posted Date: September 05, 2010    Points: 0   Category :ASP.Net
How to Retrieve image from database into gridview

View Complete Post

More Related Resource Links

ASP.Net Upload Image to MS Access Database

As you learnt from the previous articles to upload image to the SQL Database in ASP.Net 2.0 and stream that image into the memory to retrieve it from the database and display it on the web page. In this article you will learn how to upload images to the MS Access database in ASP.Net 2.0

First of all create an Access Database and place it in the App_Data folder of ASP.Net web site project. Then create a table "tblImg" with the following fields:

Can't display an image from the database



My database has a products table that has images stored in a varbinary(MAX) column.

I'm trying to display product information in a repeater and trying to display the images as well by using a GenericHandler class but I can't get the image to show up in my page.

Here is my Handler.ashx class:

Public Class Handler
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        '== Set up the response settings
        context.Response.ContentType = "image/gif"
        context.Response.BufferOutput = False

        Dim id As Integer = -1
        Dim stream As Stream = Nothing
        If Not String.IsNullOrEmpty(context.Request.QueryString("id")) Then
            id = context.Request.QueryString("id")
            stream = GetImage(id)
        End If

        Const buffersize As Integer = 1024 * 16
        Dim buffer(buffersize) As Byte
        'byte[] buffer = new byte[buffersize];
        Dim count As Integer = stream.Read(buffer, 0, buffersize)

        While count > 0
            context.Response.OutputStream.Write(buffer, 0, count)
            count = stream.Read(buffer, 0, buffersize)
        End While


Generating for each data in Database new Image

Hello everybody! I have the next problem. I have in Database about 100 rows with X and Y coordinates. I have the one image -> "Car.png" How can I in one statement show all 100 cars in my Wpf Application ? ( generate for about 100 Image objects ). Best Regards, Oleg

Displaying Image stored in rtf format in access database displaying it on crystal report

Hello, I'm working on a C# project combined with "Crystal Reports 10". When a user inserts something in a "TextField" in my C#-Program, it's saved  as RTF-code (Bolt,Pictures,Underlined,....) to a database.. So if they  reopen it in my "C#"-program they're able to see what they've entered  including their pictures .... But when I created a "Crystal Report"-file and combined it with the same  database used in my "C#"-program, it only show the formatted text and not  the pictures or images... Is there a way to show the "Picture" or "Image" they've inserted in RTF-code  ??? When I copy the code from the database in a simple Text-File and rename  it too "Test.rtf", it wil open correctly in word (with picture and  everything else)... So I hope there is a way to get the picture, Cz it's rather important  they've got a picture of the product they wanna print ...

Upload image to database - couldn't find file path

I'm trying to display images in a GridView (yes, still this...). [edit] Before I can come to that I have to upload some images to the database.I've followed this tutorial for the "upload image to database" code (this worked fine for uploading images, but I don't know if the images were converted to byte):http://aspsnippets.com/Articles/Save-Files-to-SQL-Server-Database-using-FileUpload-Control.aspxand I've followed this tutorial for the "display images in gridview" code (and "retrieve file" from the tutorial below).http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspxIt doesn't quite work, the GridView shows but without imagesNow I'm trying to change the "save file" code according to this tutorial:http://aspsnippets.com/Articles/Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASP.Net.aspxbut I don't understand everything in it. When I try to upload an image I get an error on this line:FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); //couldn't find file (path to image I tried to upload) What should I do about it?

ASP.NET: How to Load image and save to database form clientside

Hello, can any one help? I am using HTTPHandlers for loading the image from the database I need to change the image and save it back to the database from the client side, that is I need to browse image at client side and save the image as bytes in to databases, how to do this? Regards, satish  

Retrieve image from database




I have followed the example from this page for vb.net.



The upload works fine, but not the download. Everything is as the example but its not working. This in running in my development enviroment i.e httpL/localhost.

Do i have to configure my asp.net or something, or the image control on my web page.


Can anybody help.



How to retrive client name ,Field , and Image from Database and show in datalist?


hi experts,

i wanat to display Client Name, Field and  image in datalist. Stored Procedure like this

ALTER proc [dbo].[get_clients_services]
SELECT     Clients.ClientName AS Client, Fields.FieldName AS Field, ServiceType.ServiceType AS Services, ServiceType.Servicelink AS Link, 
                      Clients.ClientLogo AS Logo
FROM         Clients INNER JOIN

Can't get image to display from SQL database


Hi all,

I'm having a heck of a time getting an image to display from a SQL database.  When I view the source of the page in Firefox and then click on the link in the source for the image control, I see the following message:

The image "view-source:http://localhost:4484/mySite/Handler.ashx?m=1342" cannot be displayed, because it contains errors.

Here are the details:

The column holding the image is an "image" data type.

Code on the ~/some_members/members.aspx page:

<asp:Image ID="Image1" runat="server" />

Code behind for the members.aspx page:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Image1.ImageUrl = "~/Handler.ashx?m=" & Request.QueryString("m")
End Sub

Handler.ashx code:

<%@ WebHandler Language="VB" Class="Handler" %>

Imports System
Imports System.Web

Public Class Handler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
  Dim rdr As System.Data.SqlClient.SqlDataReader = Nothing
 Dim conn As System.Data.SqlClient.SqlConnection = Nothing

Dispaly image from Ms access database to rdlc file


hi all,

    I have done website using Ms access database and VS2005. actually i store image in system.byte[] format in MS access database..so i want to set that image in rdlc background or image tag.

actually  i did the following way..

  OdbcCommand commad = new OdbcCommand("Select img_stream from Key", con);
               OdbcDataReader dr1 = commad.ExecuteReader();

                OdbcDataAdapter myAdapter = new OdbcDataAdapter(commad);
                DataSet myDataSet = new DataSet();
                byte[] imageContent = null;
                foreach (DataRow dRow in myDataSet.Tables["Key"].Rows)
                    if (dRow["img_stream"] != DBNull.Value)

                       imageContent = (byte[])dRow["img_stream"];

                    byte[] imageContent1 = (byte[])((dRow["img_stream"]));


  this.reportViewer1.LocalReport.ReportEmbeddedResource = "Taegutec.Report2.rdlc";
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_Key", myAdapter));

but i got following Exception

ex = {"Value does not fall within the expected ra

Binary Data Problem....save and retrive image data from sql database


hello friends...please help me to solve this problem....

i have created crud (create, retive, update and delete)form and it's running... here i want to add images for each record(sql database)....

i'm using image datatype in sql table for picture.....

Q 1: how to save and retrive binary data(image) from sql table in asp.net form using vb coding?

Q2: can i create sql table which store binary(image url) data direct?

thank you

show image in gridview from sql database


how to show image in gridview from sql database

How to display image from database using MVC2 & Entity framework.



I am very new to MVC and entity I have being searching all over the internet on how to do this. Please help.

I need to do a site similar to http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx but don't know how to display or retrieve the images as in the above website.

Thank you so much!

How to save WPF RichTextBox content (text + image) to the database



I want to save (and after that also to retrieve) the content of an WPF RichTextBox (text + image) to/from the database.

I found this: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/750a654e-b002-4742-8f46-609e93f6ec81 but like the author said, the solution seams not to work for text with image - the image is ignored/removed and only the formatted text is saved and after that retrieved to/from database.

Know someone a solution about this issue?

Best regards,





Storing Image in database as image type and viewing it on grid view


 how can i store image into database and view it in grid view?

how to install image and music into a table/database

Hi can anyone refer me to a step by step tutorial or how do upload image or music into a database

Datalist not displaying image from database


My database table contains the image file path which will be stored from a
file upload control.The image path in the table will be like "C:\Projects\projectname\projectfolder\Files\1_129308367798080000_images1.jpg"

I am trying to display that image through a datalist control as follows
<asp:DataList ID="cobrandlogolist" runat="server">
                <asp:Image id="CobrandLogo" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "CobrandLogo") %>' Height="100px" Width="100px"


and i am retrieving the image names from the db and assigning as datasource of this datalist in the load event as follows

    DataTable dt = new DataTable();

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend