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

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

Retrieve image from database

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :ASP.Net



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.



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


How to retrieve image from DB with Linq and diplay in Image Control


Hi all-


I'm using the file upload to let the user upload a single file.  Here's the code I'm using to then upload to the DB.  How do I reverse this process and dowload the image into the control for it to display on a different page?

Here's my code for the upload - which I think works but can't confirm until I can see the download since all I see in the DB is "binary data"

'update DB with new Image 
        If FileUpload1.HasFile AndAlso FileUpload1.PostedFile.ContentLength > 0 Then
            'Read the file in to a byte Array.
            Dim filebyte As Byte() = FileUpload1.FileBytes
            Dim fileBinary As New System.Data.Linq.Binary(filebyte)
                Dim c3 = (From c In dc.ProductImages _
                          Where c.userID = userGuid _
                          Select c).FirstOrDefault

                c3.productImage = fileBinary

            Catch ex As Exception
                Throw ex
            End Try
Here's my attempt at the retrieval, which isn't working:
                    Dim currentImage = F

Retrieve cube data directly from Relational database - is this possible?

I have a cube created in SSAS R2 2008. Now i would like to retrieve some data from this cube, using MDX language, and then to process it in Relational SQL database! Is this possible? I am new in SSAS, please help!  

ssis sql 2000 image to 2008 varbinary Failed to retrieve long data for column

Hi, I have a task that to migrate the image type column from sql 2000 to varbinary type in sql 2008. The source column having 3812353 max datalength size for the column. The package always failed with following error message. [OLE DB Source [13177]] Error: Failed to retrieve long data for column "attch_file_content_t". [OLE DB Source [13177]] Error: There was an error with output column "attch_file_content_t" (13209) on output "OLE DB Source Output" (13187). The column status returned was: "DBSTATUS_UNAVAILABLE". [OLE DB Source [13177]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "output column "attch_file_content_t" (13209)" failed because error code 0xC0209071 occurred, and the error row disposition on "output column "attch_file_content_t" (13209)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure. Meng Chew

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

Retreiving image from database

How to Retrieve image from database into gridview

retrieve an image from sql using daab

Hello I am using daab in my web application, and 1 module requires me to insert and image and retrieve it accordingly, i would use the ID to retrieve the image, i have done this using ado.net and it works great. i am now getting used to the daab so i decided to use this. My application consists of a businesslogic layer which contains 1 class file, Images.cs. The application inserts the image and now I just want to retrieve it. I have also looked at this article...http://davidhayden.com/blog/dave/archive/2006/05/19/2948.aspx, but I cant implement the retrieve image part. Also he is using windows forms, (picture box) I am using a web form! Below is my code. First will be my business logic images class and then my web form. All i want is to retrieve my image from sql now IMAGES CLASS IN MY BLL, THIS IS REFERENCED TO MY PRESENTATION LAYERusing System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Practices.EnterpriseLibrary.Data; using Microsoft.Practices.EnterpriseLibrary.Common; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; using System.Data.Common; using System.Data; namespace BusinessLogic { public class Images { //decalre the connection string to the database using the data access block Database db = EnterpriseLibraryContainer.Current.GetI

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?

Suppose we are building a web-based application to retrieve and enter information into a database.

Please help me out with thisSuppose we are building a web-based application to retrieve and enter information into a database.  The user-interface invokes web services.  Which architecture  would use for the application.

Image retrieve

hi, i hv images in my sql database i m retrieving it using generic handler and datalist.. in datalist ihv binded the image url with Eval() expression where i m sending  image id.. the problem is if i m saving image id as a numeric data(like 123 ) no matter whether its varchar or inetger i can retrieve my image bt as soon as i m using alphabets in imageid (like NF001) i cannot retrieve image..

Retrieve SSRS Image from a particular location on server, depensng on the student ID

Hi I am a newbie and have an issue to get that particulat Student Image on the report when he is logged in with respect to student ID, the student images are stored at a particular location on server and the server path + Student id will pick the specific image.Can I make the path+ StuID+Image as a constant and use it in a report for a specific Student ID. Please advice...    

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 large file from database ?


I have a database table that works as a file repository.  Currently there are binaries stored in there and I want to pull the "large" ones out in chunks.  Some of these files are in excess of 500 MB.  I have business rules that dictate if the file is >5MB to transmit in chunks.  <5MB and I can load into memory and rip out.  I got the uploading in chunks to work, but how do I get it to pull it out of the DB in chunks?

Right now I'm getting hit with a 'System.OutOfMemory' exception.  But when I recreate the byte array of the SAME size (empty though) it doesn't break.

Download Chunks (DAL)

public byte[] getBytesByDataID(int chunkSize, string dataID)
            string query = "SELECT data.data " +
                " FROM data " +

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

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