Retrieving Images from SqlServer and displaying in a DataGrid - ASP .NET
page 1 of 1
Published: 22 Oct 2003
Abstract
Before reading this article, I assume that the reader has read my two previous articles which talks about Inserting Images to Sql Server in ASP .NET and Retreiving Images from Sql Server in ASP .NET. In this article, we will discuss about populating a datagrid with images. Of course, the images will be coming from the database.
by Jesudas Chinnathampi (Das)
Feedback
Average Rating: 
Views (Total / Last 10 Days): 196532/ 2333

Retrieving Images from SqlServer and displaying in a DataGrid - ASP .NET

Written on: May, 15th 2002.
Introduction

Before reading this article, I assume that the reader has read my two previous articles which talks about Inserting Images to Sql Server in ASP .NET and Retreiving Images from Sql Server in ASP .NET.

In this article, we will discuss about populating a datagrid with images. Of course, the images will be coming from the database.

We will be learning the following aspects in this article.
  1. Formatting or populating a URL dynamically
  2. How to read images from a sql server
  3. How to display the images in a DataGrid which is retrievied from a SqlServer

We will have two ASPX pages, one for displaying the datagrid and another one for pulling the images from sql server datbase. The one which displays the datagrid just contains the TemplateColumns, and ItemTemplates. The DataGrid will have many columns. We will just concentrate on the column which displays the image.

Code to show the image from sql server (DataGrid part).
    <asp:TemplateColumn HeaderText="Image">
        <ItemTemplate>
            <asp:Image
            Width="150" Height="125"
            ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "PersonID")) %>'
            Runat=server />
        </ItemTemplate>
    </asp:TemplateColumn>


And the method FormatURL (A Server side Function) is as follows.

    Function FormatURL(strArgument) as String
        Return ("readrealimage.aspx?id=" & strArgument)
    End Function

And the method FormatURL (A Server side Function) is as follows.

    Function FormatURL(strArgument) as String
        Return ("readrealimage.aspx?id=" & strArgument)
    End Function

How it works?

In the above code, we have an ItemTemplate column. And we have a <asp:Image web server control which is equivalent to the <img> tag. In the ImageURL property, we invoke a server side method, FormatURL, which populates the image source. In the FormatURL, you can see that, we invoke another page called readrealimages.aspx, which actually pulls the image from the sql server. The technique for retrieving the image is the same that was discussed in my other article, which deals with
Retreiving Images from Sql Server in ASP .NET. Let us take a took at the content of readimage.aspx.

Code to show the image from sql server (Talking with the Database part).
    Public Sub Page_Load(sender As Object, e As EventArgs)

        Dim strImageID as String = Request.QueryString("id")

        ' Create Instance of Connection and Command Object
        Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
        Dim myCommand As New SqlCommand("Select PersonImageType, PersonImage from das_person_real_images Where PersonID=" & strImageID, myConnection)

        ' I have used the select statement. But it would be much much better, if you
        'could write a small stored procedure which contains the above sql statement.
        ' Mark the Command as a SPROC (in case, if you wrote the stored procedure
        'myCommand.CommandType = CommandType.StoredProcedure

        Try
            myConnection.Open()
            Dim myDataReader as SqlDataReader
            myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
            Do While (myDataReader.Read())
                Response.ContentType = myDataReader.Item("PersonImageType")
                Response.BinaryWrite(myDataReader.Item("PersonImage"))
            Loop
            myConnection.Close()
        Catch SQLexc As SqlException

        End Try

    End Sub

How it works?

In the Page_Load event, we first retrieve the querystring (ID of the Person). Then we execute a Sql statement which returns the imagetype and the imagecontent from the database. Retrieving the image and writing to the browser is same as we discussed in Retreiving Images from Sql Server in ASP .NET.

Test this Script

Advantages and Disadvantages

The greatest advantage is that, since we store the images in database, more security is their. And the greatest disadvantage is that, we are making a database call for each image. So, if we have thousands of rows then, this process of retrieving image every time will result in low response time.

Download the code

Click here to download the datagridimages.aspx page
Click here to download the ReadRealImage.aspx page
Click here to download the Stored Procedures and table scripts

Conclusion

In the DataGrid, we do not have a hyperlink to click on the image. You can add another column which has a link that will be display the full image once it is clicked. You can work on this as an enhancement. If you have any trouble in getting this done, don't hesitate to email me.

Links

Inserting Image to SqlServer
Retrieving Images from SqlServer
How to Upload a File?
Textbox Web Server Control

Send your comments to das@aspalliance.com        


Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 6 and 7 and type the answer here:

User Comments

Title: retrieving image from sql server & displaying in a gridview   
Name: soubhagya biswal
Date: 8/13/2008 2:27:31 AM
Comment:
sir,
i am working in asp.net2005 using c#,sir inserting image into sqlserver is successful,but i am facing problem when to retrieve image from sql server and displaying in a gridview.sir please help me,it's very urgent,sir please provide the code in c#.
My emil id is:-soubhagyabiswal.mca@gmail.com
Title: different images   
Name: hdm
Date: 7/28/2008 1:29:15 AM
Comment:
hi
I want to use different images in one column in datagird.
how can i do that?
can i use "if else" for display datagrid?
Title: Good Idea   
Name: Ajay pandey
Date: 7/24/2008 4:30:41 AM
Comment:
It is realy a good idea and many new comers can take advantage from this code.
Thanks
Title: How do i make Image web control in ASP.NET display an image   
Name: Kenneth
Date: 7/21/2008 10:53:18 AM
Comment:
How do i make an Image web control in ASP.NET display an image with a Bitmap format, after i converted it from Byte,
---this is my code
Private Function ByteToImage(ByVal BImage() As Byte) As System.Drawing.Bitmap

Dim b As Bitmap = CType(Bitmap.FromStream(New MemoryStream(BImage)), Bitmap)

Return b
End Function
------------------------------------------------------
am getting my image Byte from a Database with a Class
and i want to display it with the Image control like this:


dim PicClass as new Picture
' After getting it from the DB
with PicClass
Image1= .PicImage
end with
-------
Pls I need your help urgently
Title: Retrieving Images from Sqlserver and displaying in a Datagrid   
Name: Jowar
Date: 7/20/2008 12:21:35 PM
Comment:
thanks for the code. Simple and well explained. You are the best. (",)
Title: Retrieving Images from Sqlserver and displaying in a Datagrid   
Name: Subhashini
Date: 7/1/2008 6:23:58 AM
Comment:
I like the article.Very informative.I could not guess out fully how the output will be.However I could get the point that connected data access is used and only one image can only be viewed at a time.Is there a way to store images in dataset and retreive from it.Is it possible? Hope I will try and get it.
Title: Displaying image in datagrid   
Name: Noufel
Date: 6/25/2008 3:24:12 AM
Comment:
Superrrrrrrrrrrrrrrrrrrrr.Txs a lot
Title: Multiple images in same page   
Name: Nidhin
Date: 6/24/2008 3:17:41 AM
Comment:
Hi,
I need to print multiple images in same page with this method .I can display images but not in currct order.ie,All images are displaying random.How to display in the currect order.Plz reply here or send the code nidhinrc@gmail.com.
plz any one reply as much as possibal

Thanks & Regards,
Nidhin
Title: intraction with db   
Name: raj
Date: 6/20/2008 1:56:24 PM
Comment:
Iam doing school project, I want intract with db from frontend registration form for retriving & updation data
Title: retrving images ti gridview   
Name: kiran
Date: 6/19/2008 8:12:46 AM
Comment:
thanks a lot
i inserted images to database.
when i am retreving the image sto gridview how can i pass the value to querystring.
i didn't get images in data grid
please send the code kiran.224@gmail.com
Title: Thanks   
Name: kiran
Date: 6/19/2008 7:46:50 AM
Comment:
hi thanks,
when i am executing how can i give query string id .
Request.QueryString("id")
Title: Bakwas   
Name: Bakwas
Date: 6/12/2008 4:52:31 AM
Comment:
If Request.QueryString.Get("Id") IsNot Nothing Then
Response.Clear()
Dim id As Guid = New Guid(Request.QueryString.Get("Id"))
Dim myFile As File = File.GetItem(id)
Response.ContentType = myFile.ContentType
If myFile.ContainsFile Then
Response.BinaryWrite(myFile.FileData)
Else
Response.Redirect(Path.Combine(AppConfiguration.UploadsFolder, myFile.FileUrl))
End If
Else
Response.Redirect("~/")
End If
End Sub
Title: Thanks a lot   
Name: Buddika
Date: 5/29/2008 7:23:45 AM
Comment:
Thanks for this article, its really helpful for me.
Title: In panel or textbox   
Name: Deepa
Date: 5/23/2008 2:04:40 AM
Comment:
Thnx for article, can retrieve image in panel or textbox?
bcoz whn i enter employee id i want picture of that employee in textbox or panel
plzzz help me

Thnx & Regards,
DeepaG
Title: very good   
Name: narender
Date: 5/15/2008 5:49:47 AM
Comment:
it is very good and so much help to my problem,but i have another query,how to crate a excel file dynamically with sheetname
Title: retrive image from databse   
Name: neeraj
Date: 5/6/2008 9:11:29 AM
Comment:
thank's for help me it's realy a good way to do your project reduce the code size theank u once again dost
Title: Open Window   
Name: Abraham
Date: 4/8/2008 6:31:48 AM
Comment:
This is a good script, thanks for your help. But I am facing a problem...It is showing image in different window when I try to load. i have a lay out. How can i show the images in the same wondow (_self)? my URL is something like domainname/default.aspx?pageid=107
Title: hi   
Name: Amol Kagde
Date: 4/7/2008 12:43:23 AM
Comment:
hi

this article realy help me......

thank u!
Title: Verygood   
Name: Nice
Date: 4/3/2008 6:13:28 AM
Comment:
very good
it's too easy
i west my one week behind this problem
but from above solution i got the solution of my problem within a few minutes
thanx again
Title: thanks   
Name: pooja shah
Date: 3/8/2008 4:47:29 AM
Comment:
this article is really a very good article ..
i really liked it..
it has solve my problems of how to upload images
Title: Thanks   
Name: suma
Date: 3/3/2008 7:30:59 AM
Comment:
The information given by u is nice.But when i use the following lines in c#

Response.ContentType = myDataReader.Item("PersonImageType")
Response.BinaryWrite(myDataReader.Item("PersonImage"))

iam unable to find the Item Property as there is no item property in c#.So plz can u help in this issue..
Title: thanks   
Name: ash
Date: 2/19/2008 6:06:58 AM
Comment:
i want to now that if i hv inserted 20 images of a single user
at the time of registration that images are blank. now i hv to retrive that images in datalist and in my datalist i hv to display 20 diff images from that database but when i will insert that time it will take only one image and all 20 images in database will be same .
so plz rply me code how can i display 20 diff images of single user
Title: Thnks   
Name: Shafiq
Date: 2/13/2008 5:14:23 AM
Comment:
i got ideas from this
it is really good
Title: i really thankful to you for this help...   
Name: Rana Omair
Date: 2/13/2008 1:01:01 AM
Comment:
thanks..its really helpful for me...and new commers.as well.
Title: Great!!   
Name: Kristof 'kleine'
Date: 1/30/2008 10:18:30 AM
Comment:
Thank you so much for this post, it was very helpfull in order to complete my latest project.
Please Continue doing such a great job!
Title: displaying image in datagrid   
Name: sravan
Date: 1/21/2008 6:28:44 AM
Comment:
can u please send me how to retriew images to the datagrid from database in the serial order which i had saved in it(images saved in database) not from url but directly from database
Title: displaying image in datagrid   
Name: pradeep
Date: 1/21/2008 6:15:21 AM
Comment:
its good but i waNT SOMETHING more .can u please send me how to retriew images to the datagrid
Title: Thank you   
Name: Noora
Date: 1/21/2008 5:45:40 AM
Comment:
Realy usefull and simple.
Thank you
Title: programing +truth table (and,or,conditional statement)+c++ +show execute   
Name: neda
Date: 1/13/2008 5:10:40 PM
Comment:
I NEED TO HELP ME FOR THIS PROGRAM AND RESULT PLZ
Title: i'm getting problem   
Name: Viral Vyas
Date: 1/5/2008 2:20:26 PM
Comment:
plz any one reply as much as possibal
i have read many of code and smple which showes how to add imgage in grid view from sqlSever but i can't getting full help i mad lost of code from internet but failed to retiver so plz maill me full code with expenetion to me on vikivyas@gmail.com
i will be very thnak full if you help me
Title: about CommandBehavior   
Name: aa
Date: 12/31/2007 3:29:31 AM
Comment:
when i paste the above code in my form a following error has been occurred whats the solution for this problem

"Name 'CommandBehavior' is not declared"
Title: Good sample   
Name: Andrey
Date: 12/28/2007 4:11:56 AM
Comment:
Realy usefull and simple. Thanx a lot!
Title: sir my problem is that suppose there are 50 records in the database and i want to show last 10 records in the grid view   
Name: Amit mittal
Date: 12/20/2007 1:30:47 AM
Comment:
sir my problem is that suppose there are 50 records in the database and i want to show last 10 records in the grid view and it will retrieve only that 10 records from the database not all
Title: Help   
Name: Sioux
Date: 12/6/2007 7:05:06 PM
Comment:
Thanks for the code, it works fine but the image is not displayed in the datagrid, I only get an X.
Did anyone solve this problem?
Please reply to susanna_pecora@hotmail.com
Title: Retrieving images from uploaded folder   
Name: Software Engineer Amjad Hussain
Date: 12/6/2007 6:40:14 AM
Comment:
Thank you for your response sir, i could upload the forder in asp.net but there is one problem to get the exact path of that server on which our project is running. please convey the solution.
Title: Retrieving images from sql server 2000   
Name: Software Engineer Mumtaz Ali
Date: 12/6/2007 6:35:52 AM
Comment:
there is one problem to retrieve the picture from sql 2000 . it is accessed but how to display in a image1 control .
Title: retreiving image   
Name: veerapathiran(phenos)
Date: 11/30/2007 11:55:53 AM
Comment:
hai,
ur coding is easy to understood all..thank u for ur helping mind....
my question: i easy to upload the image for sql server 2ooo data base..but i don't retreiving a image from sql server 2000 data base to asp.net with c#(contros using datalist)..plz how can retrieve the image to datalist control from sqlserver 2000 ..plz reply to me.....
it's very urgent need..plz sir plz......
please post me the code to kalai_veera@sify.com or kalai_veera@rediffmail.com
Title: i want a retrive delete images code   
Name: veena khan
Date: 11/29/2007 9:48:19 AM
Comment:
hi h r u
i just wana say u that i ve some problem in retrive n delete image
how can i retrive n delete images in vb.net2003 using sqlserver2000
plzzzzzzzz
its very urgent
plzzzz
do give me favour
my email is
elite_onlinz@yahoo.com
Title: display image   
Name: sadanandam
Date: 11/29/2007 6:04:34 AM
Comment:
hello ,i want to retrieve the image frm the sql server 2005
and place it an the image conrol plse reply me .plse reply me to sadanandam_mca@yahoo.co.in
Title: Display image   
Name: Sowjanya
Date: 11/28/2007 2:05:51 AM
Comment:
Hello sir,
I want to retrieve an image from sql server 2005 and place it in an image control in c#.net 2.0.
Please post me the code to
sowjanyaposani@gmail.com
Title: mmm...   
Name: Miron
Date: 11/20/2007 9:27:22 AM
Comment:
Saving images in the db is'nt so good idea, special from the reason of the difficulties of show them on the screen.
Opening connection to DB fr every image is a really bad thing to do!
Save your images in a floder, an the names only in the db.
If you concern from security, so disable access to the images directory from your Web.config
Title: Can't display an image   
Name: Nono
Date: 11/12/2007 1:34:09 AM
Comment:
Im using VB in VS2005, SQL Server 2005 and i using the example pages and code posted here, but the datagrid only shows a red 'X' in the column of the image, and all the other columns shows their correct values, somebody knows why the column of the image dont show the image?
thanks...
Title: how we update a single record in datagrid using C#   
Name: Amit s Umredkar
Date: 10/31/2007 12:48:37 AM
Comment:
sir,
i want to update a single or particular record in datagrid and only to view a single record how i can do this plz tell me
Title: how do this for c#?   
Name: putianlei(putianlei@163.com)
Date: 10/30/2007 9:49:30 PM
Comment:
I want to know :how do "Response.BinaryWrite(myDataReader.Item("PersonImage"))" in c#?
Title: Retrieving Images from SqlServer   
Name: Swarup
Date: 10/30/2007 5:29:40 AM
Comment:
Tru myDataReader["PersonImageType"]
Title: Retrieving Images from SqlServer   
Name: kavya
Date: 10/25/2007 1:13:32 AM
Comment:
In following lines getting error:as there is no item property in c#.how to replace:
Response.ContentType = myDataReader.Item("PersonImageType")
Response.BinaryWrite(myDataReader.Item("PersonImage"))
kavita.dhoot@rediffmail.com,
waiting soon to hear from you
Title: Retrieving Images from SqlServer   
Name: karthi
Date: 10/18/2007 1:17:05 AM
Comment:
sir/madam,

i have seen your site for my doubt Retrieving Images from SqlServer, yet i haven't get solution from your site...
i know your site is only link but not solution
Title: how to insert an image into datagrid   
Name: minati
Date: 10/12/2007 6:04:02 AM
Comment:
It was really interesting to find the code. Now my problem is solved to gud extent. Thanks to all the family members of the site u make the world move smooth. the help
Title: how to show two table in one detagrid through stroed procedure   
Name: Amit Singh
Date: 10/7/2007 2:41:27 PM
Comment:
I am trying to show 2 table in one datagrid(using ASP.NET & C#.NET) through Stroed Procedure(sql server2005), but in query(in Stroed Procedure), show error. Can u help me....?
My mail id is "m4aksingh@gmail.com".
Title: http handler   
Name: Maitry Panchal
Date: 9/13/2007 1:14:02 AM
Comment:
i tried your code to retrieve image from databse. Actually i want to display images in datagrid with help of http handler.my project is Blog creation application n i want to display friend list with corresponding images in my myfriend list form
Title: It Works But Some Changes Required   
Name: Subhajit Sarkar
Date: 9/12/2007 6:55:07 AM
Comment:
Changes required in store procedure and some coding in asp.net. but it works fine.
Title: Its giving an error   
Name: Brendan Barghus (brendan@neametrics.com)
Date: 8/31/2007 10:58:46 AM
Comment:
I am getting the folling error on binding the datarid to the dataset (There is no row at position 0). Is there anyway you can help me on this error.
Title: It works   
Name: Rudolph
Date: 7/25/2007 9:04:42 AM
Comment:
If you are struggeling to get this to work then email me and I will send you a step-by-step example of how to upload images and displaying it using a grid.
rudolph@networkdeals.co.za
Title: MR   
Name: Anbu
Date: 7/25/2007 3:27:27 AM
Comment:
It is good.Thanks
Anbu
Title: Mr   
Name: Simon
Date: 7/16/2007 2:48:11 PM
Comment:
This is very useful to any one,its my first time to use asp.net but I now feel like a proffessional somebody.
Siplifies life for Developers
Title: Help full   
Name: muthu
Date: 7/11/2007 11:02:07 AM
Comment:
coding would be very useful to developers thank u
Title: nice Article   
Name: adams
Date: 7/11/2007 6:05:48 AM
Comment:
if you have code for retrive image from sql server into windows picture box in vb.net 2003

Because it only works in ASP
Title: Hw to Update image in datagrid   
Name: Leela
Date: 7/10/2007 8:16:38 AM
Comment:
i wanted to update image , i m able to upload image to dB but unable to update the image if any i do updation. Pls reply me regarding this as soon as possible
Title: please heip me   
Name: sudheer
Date: 7/3/2007 12:30:42 AM
Comment:
hello this is greate code.but my problem is images are inserted into the database.but my client requirement is at the retrieving time that image must be open in Microsoft Office Picture Manager .but my image is opened in another browser how is it possible.how can i open image in Microsoft Office Picture Manager.
Title: Programmer   
Name: chitra
Date: 7/2/2007 4:24:43 AM
Comment:
Hello Sir,
I did what you told to do but this is giving me an error
Error 1 The best overloaded method match for the file name has some invalid arguments
Error 2 Argument '1': cannot convert from 'object' to 'string'

do you have any other solution for this?
thankfully
chitra
Title: SE   
Name: Sathiskumar.P
Date: 6/30/2007 5:39:45 AM
Comment:
How to assign retive image from SQL Server 2000... to image control in asp.net,C#.net....

Help me.......
Title: display tiff image in Datagrid   
Name: K A Bhuva
Date: 6/27/2007 3:50:01 AM
Comment:
In your Code Display .jpeg and .gif but i want to display .tif image in datagrid please help me.

It's very urgent
Title: how to retrieve the text file from access database   
Name: santosh
Date: 6/24/2007 2:04:59 PM
Comment:
plz. send me(santoshjsh@yahoo.com) the code for retriving the text,doc,img file from access database uploaded using fileUpload web control in vb.net. and how to show it in asp.net web form. as soon as possible.
thanking you
Title: Save Images in a Folder in the Application for Display in GridView   
Name: Umesh
Date: 6/22/2007 2:12:45 PM
Comment:
I store image selected by the User in a folder in the Application with a Unique FileName. But in an Edit mode if the User happens to change the image, the new image is also stored with the same name(prev image overwritten) in the folder.

A gridview which shows the record along with the image doesnt show the new image after the update. Its only after the application is restarted does the new image appear.

Can U help me with this..

Cheers
Title: How to save images in SQL Server   
Name: Srikanth
Date: 5/29/2007 5:03:29 PM
Comment:
Hello,

Can some one of you guys,help me how to save images in SQL server by giving path of images. and also how to display them on web pages.It would be really helpful for me if someone can send me the sample code for doing this in C#.Please email me at srikanth.neu@gmail.com

Thanks,
Srikanth
Title: cant able to edit or update a datagrid in vb.net   
Name: Priya
Date: 5/28/2007 3:09:51 AM
Comment:
i hav used datagrid to merge the database, i dont know the code used for edit,update and delete command in the datagrid even though i placed a button item from property builder->columns->button, but i dont know how to write the code for that
Title: nt getting respone   
Name: lopamudra
Date: 5/23/2007 4:52:17 AM
Comment:
i have dropped 3 mails rgding my doubt code, which im using ur code "Retrieving Images from SqlServer and displaying in a DataGrid" .
bt till now im nt getting any response.
can i have wht is d problem?

thanx & regards
Title: nt passin d parameter   
Name: lopa
Date: 5/22/2007 8:47:14 AM
Comment:
grid.aspx.vb
-----------------

Function FormatURL(strArgument) as String
Return ("readrealimage.aspx?id=" & strArgument)
End Function

pullinimage.aspx
-----------------------

Dim strImageID as String = Request.QueryString("id")

function is nt takin any parrameter 2 d next page.
b'cs image page is nt takin any value in query string

plz.......tell me d solution.
Title: doubt   
Name: lopa
Date: 5/22/2007 7:58:51 AM
Comment:
im nt getting d image column bt d sno(ID) ids diaplayin.
while workin with data grid.
bt retrieving image is workin while it is nt in grid.

plz.....help me.
Title: A page can have only one server-side Form tag.   
Name: lopamudra
Date: 5/22/2007 6:06:59 AM
Comment:
after running the gridview page. im getting this error msg in browser "A page can have only one server-side Form tag."
i have used form tag in gridview page.
plz..........let me clear abt it.

waiting
lopashree@rediffmail.com
Title: system.configuration   
Name: lopamudra
Date: 5/22/2007 1:16:58 AM
Comment:
hello sir,
Im workin in asp.net 2.0 and vb language. so it's nt takin support of system.configuration. so im nt able to run my code Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
dr = com.ExecuteReader(CommandBehavior.CloseConnection)
kindly give me idea........
Title: System.Configuration   
Name: lopamudra
Date: 5/22/2007 1:05:04 AM
Comment:
Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
dr = com.ExecuteReader(CommandBehavior.CloseConnection)

I am getting error in ConfigurationSettings.AppSettings and CommandBehavior.CloseConnection in my aspx. i added namespace System.Configuration.bt it is nt solved.
Kindly tell me wht is the solution?

lopashree@rediffmail.com
Title: Nice explanation   
Name: venkat
Date: 5/16/2007 9:20:56 AM
Comment:
Nice explanation.but i need this one in delphi programing.from few days onwards iam getting this problem .plz help me.thanQ
Title: easy steps for connectivity   
Name: j.c.vivek
Date: 5/15/2007 8:29:49 AM
Comment:
i am beginner for .net.how to connect the database in easy way. and steps to connect the database.
Title: Please help me   
Name: Yogesh Parihar My Email- parihar_yogesh@yahoo.com
Date: 5/15/2007 12:57:09 AM
Comment:
hi sir,
please help me. Iam doing MCA 6 sem project. Project is Online shopping. In that project ,I want to stroe images in database. What is the code for storing & retrive image from Sql Server.My Project Frontend ASP with VBScript & Backend is SQL Server.Again I Specify My project is on ASP not on ASP.Net bcoz.i have solution of abouve problem in .NET but I am working on pure ASP with VBScript.I am totally harassed becoz no one help me at these movement.Please help me sir.
Title: cant display images   
Name: Bimal
Date: 5/10/2007 2:26:36 AM
Comment:
Hi
i'v use your codes for uploading images to successfully. But in displaying images code i got a problem.And iv try to displaying images in readrealimage.aspx page separately and i got this error "System.InvalidOperationException: Byte[][1]: the Size property has an invalid size of 0.".I cant understand this error can u please help me.
Title: how we can bind a text data(notepad) with asp.net plz do mail me with code   
Name: savita Singh
Date: 5/7/2007 6:05:23 AM
Comment:
how to bind text data with datafris then insert into sql server2000.
insert data will be displayed in to sql
Title: how to binding immages in datagrid codeview   
Name: sreedhar
Date: 5/4/2007 7:27:42 AM
Comment:
hi sir i want to lot of immages binding to datagrid how and also plse giveme code.
and the images(person is immage heis having name,place etc) displayed in datagrid
how plase
helpme
Title: problem displaying image   
Name: Veronica
Date: 5/4/2007 6:32:17 AM
Comment:
Hello,

Your code is great but I have a problem. If I leave the where condition out, an image is displayed. But when trying to select a special image none is shown. Could you please give me a hint of what might be wrong? (If I write a number instead of the variable "strImageID" everything works fine)

Thanks a lot and kind regards,

Veronica
(ve.nokta@gmail.com)
Title: pls help me am using c#   
Name: yogarajan
Date: 5/2/2007 12:59:45 AM
Comment:
Hi

i have one doubt abt datagrid (using c#). pls help me

here is my code

//** code start here**

Page_Load event:

DataSet ds = BuildDataSet();
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

private DataSet BuildDataSet(){ DataSet ret = new DataSet(); DataTable dt =
new DataTable(); DataRow dr = null; // Define table column names and datatypes DataColumn dc =
new DataColumn("ID",Type.GetType("System.Int32")); dt.Columns.Add(dc); dc = new DataColumn("Name",Type.GetType("System.String"));
dt.Columns.Add(dc); dc = new DataColumn("Date",Type.GetType("System.DateTime")); dt.Columns.Add(dc); // Fill the table with sample data
for(int i = 1;i < = 10;i++) { dr = dt.NewRow(); dr["ID"] = i; dr["Name"] = "John Smith";
dr["Date"] = DateTime.Now.AddSeconds(i * 10); dt.Rows.Add(dr); } // Return the dataset to the caller ret.Tables.Add(dt);
return ret;}
//**** code end here**
here i have add one more column with link . how can i add?

pls help me. pls send code immd
am waiting for ur reply
i want to be utput looks like this

ID Name Date URL
1 John Smith 1/1/2007 Hyper Link

2 John Smith 2/2/2007 Hyper Link
Title: C# Code   
Name: Silgia
Date: 4/26/2007 6:30:16 AM
Comment:
Code to show the image from sql server (Talking with the Database part).
-----------------------------------------------------------
if (!string.IsNullOrEmpty(this.Request.QueryString["ID"]))
{
int ID = Convert.ToInt32(Request.QueryString["ID"]);
SqlConnection con = (new globals()).Connection;
string str = "select " + BaseClass.NameofField + " from " + BaseClass.NameofTable + " where " + BaseClass.NameofConField + "=" + ID;
SqlCommand cmd = new SqlCommand(str, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

while (reader.Read())
{
Response.BinaryWrite((byte[])(reader[BaseClass.NameofField]));

}
con.Close();
con.Dispose();
}
Title: problem   
Name: Shilpa
Date: 4/23/2007 8:52:24 AM
Comment:
hi sir,
please help me. Iam doing my sem project. Project is Online shopping. In that project i need to load many images at one time to datagrid. In database i stored only the path and i stored all the images in a folder. What is the code for loading images to datagrid. Please help me sir.

my email id is shilpa8120002000@yahoo.com
thanking u
shilpa
Title: problem   
Name: shilpa
Date: 4/23/2007 8:51:13 AM
Comment:
hi sir,
please help me. Iam doing my sem project. Project is Online shopping. In that project i need to load many images at one time to datagrid. In database i stored only the path and i stored all the images in a folder. What is the code for loading images to datagrid. Please help me sir.


thanking u
shilpa
Title: ploblem   
Name: sunny
Date: 4/19/2007 2:34:19 AM
Comment:
sir this code only one image dispaly i want all images display help me my sunny_bindr@yahoo.co.in
Title: Retriving images from database and display   
Name: Rajesh Kumar Singh
Date: 4/14/2007 2:02:10 AM
Comment:
This code has be perfact for retrive image.
Title: problem   
Name: sunny
Date: 4/10/2007 8:48:50 AM
Comment:
you r retive code is not work in data grid so please check the code sql to data grid
Title: Retriving images and display   
Name: Som
Date: 4/9/2007 1:37:35 PM
Comment:
sorry guys...my id is : som4s3@yahoo.com
Title: Retriving images and display   
Name: Som
Date: 4/9/2007 1:36:27 PM
Comment:
anyone can send me c# code
Title: Retrieving image and display   
Name: Sankar Prasad Giri
Date: 4/3/2007 12:16:14 AM
Comment:
This image retrieving code is really perfect and work it very well
Title: retrive the image   
Name: ann
Date: 3/30/2007 4:13:51 AM
Comment:
convert this code in c#
mailid: sshaalini41@gmail.com
Title: Retrieving Images from SqlServer and displaying in a DataGrid - ASP .NET   
Name: ann
Date: 3/30/2007 3:08:31 AM
Comment:
can anybody help me how the same code work in c#(ASP.NET)
Title: Displaying imagesq   
Name: Narender
Date: 2/26/2007 6:48:42 AM
Comment:
Hi this is narender. i tried getting the images from the database. but when i want to display all the images which are in the sql database i was not able to show it. my code is showing only the 1st image.Can any one help me out of this problem.And here is my code.



Dim con As New SqlConnection(ConfigurationSettings.AppSettings("GMR"))
Dim cmd As New SqlCommand
strsql = "select * from images "
Dim ds As DataSet
ds = ExecuteDataset(strsql)
Dim dt As DataTable
dt = ds.Tables(0)
Dim row As DataRow
For Each row In dt.Rows
Dim image As Byte()
image = CType(row("imageurl"), Byte())
Response.BinaryWrite(image)
Next
Title: Retrieving Images from SqlServer and displaying in a DataGrid   
Name: sara
Date: 2/22/2007 2:46:22 AM
Comment:
can you please provide the above code in c#,it would be very helpful of u.
mu emailid is sara.j1980@yahoo.com
Title: C# example   
Name: Mathew Philip Palliampil Kandankavu Areeparampu
Date: 2/12/2007 2:19:06 AM
Comment:
Great Example... Please provide the code in C# also..
Title: Hi have a problem   
Name: quine
Date: 2/6/2007 3:01:45 PM
Comment:
Hi have a problem, copy the code but the column image, me there does not stamp(print) the photos, which can be the mistake?
Title: paging datagrid   
Name: Henry
Date: 2/2/2007 3:52:46 AM
Comment:
The code i got to insert and retrieve information in database is good but i can't navigate on the grid please how do i do paging with your the code.Thank you
Title: DMW   
Name: Trainees
Date: 2/2/2007 1:13:32 AM
Comment:
Uncle please write this code in c# language and using grid view in asp.net 2.0.....thankyou
Title: My problem is solved   
Name: Henry seibenimo
Date: 2/1/2007 5:18:33 AM
Comment:
Thanks a lot,my problem of using images with a database is solved .Keep up the good work
Title: Retrive Image   
Name: sachin gupta
Date: 1/30/2007 1:03:50 PM
Comment:
I am Testing in myself Image Retrive from DataBase(SqlServer). But I run only one form. and retrive image.

Like .. In Button1_Click Event Fire And Image show In Image Control.
Title: Good   
Name: Nityanand
Date: 1/30/2007 4:01:46 AM
Comment:
This Is Very Good Example For any Developer and i like to say Thanks Very Much and Happy Programming

Best Regards,
nitya
Title: Comment on this article   
Name: Balaji
Date: 1/24/2007 1:53:57 AM
Comment:
This is best as on the freshers,But only code in vb some better to prefer for c#.
Title: how to retrieve path from database   
Name: ashas
Date: 1/20/2007 12:44:24 AM
Comment:
hello,
I have stored the image's path using htmlinputfile control in asp.net in the Access.and now i want to updata it how can i retrieve the path from the Access to htmlinputfile.
I tried to use htmlinputfile's value property.
Title: Retrieving and Inserting Images   
Name: yesupatham
Date: 1/12/2007 4:12:39 AM
Comment:
Really helpful ! good job !!
Title: Retrieving images from SQL Server   
Name: TN
Date: 1/4/2007 8:52:38 PM
Comment:
Hi, thanks for putting the code online. I tried you code, but for some reason the datagrid does not display the image. I went over the code a couple of times to check for errors. Any suggestions anyone?
Thank you.

nakhjot@optonline.net
Title: wonder!   
Name: sreekanth
Date: 12/22/2006 5:24:09 AM
Comment:
Hi
Iam sreekanth yor code is very simple and understadable
you done grate job. this is usefull for lot of developers
Thank you & keep it up
Title: Mast   
Name: Neeraj
Date: 12/12/2006 4:21:54 AM
Comment:
Thanks a lot
Title: This Code Works Fine   
Name: harry
Date: 12/11/2006 4:55:55 AM
Comment:
Great JOB, solve my problem
Title: Too many calls to database   
Name: Khurram
Date: 12/5/2006 10:38:28 AM
Comment:
The article is very useful but i have just one remark. Is this a good idea to query the database for each image isnt it too constly??
Like if you are displaying 50 records in your datagrid you will be doing fifty queries to your database for each image???
Title: How do I update the image file?   
Name: Bama
Date: 11/28/2006 11:16:56 PM
Comment:
How do I update the image file in the database after uploading?
Title: Retrieving image from sql server   
Name: kiran
Date: 11/14/2006 4:57:26 AM
Comment:
could anybody can send me code for binding image to image control from sql server.my id is raj_514@yahoo.co.in..
thanks in advance
Title: Retrieving image from sql server   
Name: kiran
Date: 11/14/2006 4:55:56 AM
Comment:
could anybody can send me code for binding image to image control.my id is raj_514@yahoo.co.in..
thanks in advance
Title: How to display full-size image?   
Name: William
Date: 11/12/2006 9:46:54 AM
Comment:
very good artical, but I am confused how to display full-size image in new window? Thanks
Title: retrieving image   
Name: ramanji
Date: 11/10/2006 8:42:39 AM
Comment:
gooooooooooooooooooooooooooooooooooooooooooooooooooooooood
Title: Retrieving Images from folder connected with SQL   
Name: Mirko
Date: 10/31/2006 5:24:46 AM
Comment:
Is it possible to write all images to a folder which is located in server and from that folder the image has to be retrived...can u just send me the details...my mail is mirko.radic@inet.hr
Title: gr8   
Name: ANTONY THURUTHEL
Date: 10/30/2006 6:56:00 AM
Comment:
GUD JOB even guys who just started can understand ur example
Title: work   
Name: ssr
Date: 10/28/2006 11:32:48 PM
Comment:
good job done sir thanks
Title: Retrieve Image & Show in Image Control   
Name: Prajyot
Date: 10/19/2006 1:59:43 AM
Comment:
Hi , Your code is very nice but I want to show retrieved Image in Image Control .Plz reply me on prajyot.mahindrakar@rediffmail.com
Title: Programmer   
Name: Saju Vetiyatil
Date: 10/12/2006 10:46:18 AM
Comment:
Dear,

Thanks for posting this . I have used to great benefit.

I would like to add that you can directly write :
<%# "readrealimage.aspx?ID="+databinder.[...].Tostring()#%>

instead of passing it through a function...

My personal E-mail ID is sajuvn@yahoo.com.

Thanking you once again,
Saju
Title: Retrieving images from sql server   
Name: rajeev kumar
Date: 10/12/2006 3:24:54 AM
Comment:
I am not bee able to display image in data grid column header shown instead of images

please help me rajeev_raja2k@yahoo.co.in
Title: asp.net datagrid   
Name: rukmang
Date: 10/11/2006 11:32:57 AM
Comment:
u have helped me alotttttttttt. great programming.
Can u please send me such articles at
rukmang_r@yahoo.com
Title: image with dotnet   
Name: rukmang rege
Date: 10/11/2006 10:06:12 AM
Comment:
too good articles"http://aspalliance.com/articleViewer.aspx?aId=141&pId=". Excellent.keep up the good work

Can you please send me such articles at
rukmang_r@yahoo.com
Title: Newbie question   
Name: Achmad Fienan R
Date: 10/5/2006 1:59:04 PM
Comment:
Hi,
I found out that your articles are useful for me. But can you give me the alternative way to write above code in ASP 2.0 with vb.net 2005? thanks

I am still a newbie, so I'm easily lost

By the way, if you dont mind. can you give me the explanation through my email? Its v_none@lycos.com
Title: Your code doesn't show the image in DG...   
Name: Vivek
Date: 9/24/2006 12:12:28 PM
Comment:
Your code doesn't show the image retrieved from the database in the database. Where is the exact code....
Title: Retreiving Images from Sql Server in ASP .NET   
Name: Manoj
Date: 9/20/2006 8:17:14 AM
Comment:
This code did a good job
Title: How to Display Images in C#   
Name: Shaju
Date: 9/12/2006 9:22:36 AM
Comment:
Really it is very good code. But I want C# code. I am modifiy this code for C# but it canot work FormatURL function. I am writing FormatURL function in first form like "Public string FormatURL(string strArgumet)"Is it corect? Please help me
Title: Retrieving Images from Sql Server   
Name: Ved Prakash
Date: 8/31/2006 8:12:10 AM
Comment:
This is very nice code.
Inquiry: I want to know that can i also join you.
I am working as a Programmer with IT company from last 6 Month.
Title: Retrieving Images from Sql Server   
Name: Kriss
Date: 8/16/2006 2:45:17 AM
Comment:
In datagrid how to display images is ok but if a particular record does not contain image URL then the image for that control does not exist how to avoid the image template by displaying in the datagrid. plz mail me to kriss_is4u@indiatimes.com
Title: Retrieving images from SQL-Server   
Name: lakshmi
Date: 8/15/2006 3:00:17 AM
Comment:
I just want toknow wht is "id"

Function FormatURL(strArgument) as String
Return ("readrealimage.aspx?id=" & strArgument)
End Function

what is "id"

Pls give answer to lak952000@yahoo.com
Title: Retrieving Images from SqlServer and displaying in a DataGrid - ASP .NET   
Name: Ericks
Date: 8/13/2006 3:46:57 AM
Comment:
This works of marvel, has extracted me of the difficulty, say to me how I publish the code that I generated with yours
I have difficulty to write this in English, wait that this good
Title: Retrieving Images from Sql Server   
Name: deepthy
Date: 8/11/2006 1:25:11 PM
Comment:
Function FormatURL(strArgument) as String
Return ("readrealimage.aspx?id=" & strArgument)
End Function

Dim strImageID as String = Request.QueryString("id")


In request.querystring("id")- What is id? (Which id)

how to run?
First i shd run readrealimages.aspx and then i shd run datagridimages.aspx
Title: Retrieving Images from Sql Server   
Name: Argie K. San Pascual
Date: 7/16/2006 11:49:25 PM
Comment:
Thankyou Very Much !! It's a very informative article.
Once again Thankyou..
Title: asp   
Name: itua
Date: 7/16/2006 2:19:14 PM
Comment:
Thank you for ue help but i would like to get a code to send emails with asp also
Title: Retrieving Images from SqlServer and displaying in a DataGrid - ASP .NET   
Name: Argie K. San Pascual
Date: 7/11/2006 8:53:49 PM
Comment:
Its a very good Code! Thanks...
Title: retrive an image from database   
Name: gayatri
Date: 7/11/2006 4:47:36 AM
Comment:
this is my id gayatri.sheethal@gmail.com plz send me to this id.
anyone can help me waiting for reply
Title: How to retrive image from database by selecting in dropdownlist   
Name: gayatri
Date: 7/11/2006 4:45:00 AM
Comment:
this is nice but i have another dought by selcting the id in dropdown i must get image from database and display in the image control.plz anyone can helpme.
regards gayatri
Title: dot netq   
Name: jay
Date: 7/10/2006 2:46:19 AM
Comment:
hi i know the indepth
Title: Retrieving Images from Sql Server   
Name: Henrique R. Brandao Neto
Date: 6/30/2006 9:24:09 AM
Comment:
thanks a lot for this helpful article, I had only to increment one thing on my code:
ImageUrl='<%# "view.aspx?id=" & System.Convert.ToString(DataBinder.Eval(Container.DataItem, "id")) %>'
Thats because my Photo Code column in our database is integer. I think so. Regards Henrique/Brasil
Title: error at datareader.item   
Name: kranthi
Date: 6/22/2006 8:34:07 AM
Comment:
Response.ContentType = myDataReader.Item("imageType");
Response.BinaryWrite(myDataReader.Item("myimage"));
does not contain identification item
Title: Doubt   
Name: Jhanani
Date: 6/21/2006 2:55:25 AM
Comment:
<%@register tagname="Acme" TagPrefix="LeftMenu" src="use1.ascx"%>.The above statement can't work in Microsoftvisual studio.net

When i write the same in notepad it is working.
So how to write the same statement in codebehind

plz help
jhanani
Title: Good Show!!!   
Name: Ramaraj R
Date: 6/20/2006 1:49:23 PM
Comment:
Hi Guys,

Really appriciated for helping me through this code....
Title: Mr   
Name: naresh
Date: 6/20/2006 7:58:56 AM
Comment:
good but i have some doubts. can u tell me if there is no field with image type. and if it is bitmap can write image type as bitmap
Title: Images in Datagrid   
Name: nagendra
Date: 6/18/2006 6:02:38 AM
Comment:
Hi,
It's really nice code. I have 1 doubt. Plz reply me. We r using ReadRealImage.aspx to retrieve images. why don't we use this code in datagridimages.aspx itself. is it possible ? I tried but failed. plz post code or give idea. Thanks in advance. my id: meet_nagendrap@yahoo.co.in

plz help !!
Title: Unable to display images   
Name: Ani
Date: 6/8/2006 5:35:37 AM
Comment:
I ahve tried to use the same code but i run into the error
The image “http://localhost:1935/ContentKiosk/WidicoServices.aspx” cannot be displayed, because it contains errors.
I am using C# and ASP.NET 2.0
Please reply to anitha.reddykora@gmail.com
Its urgent.Please help
Title: Unable to disaply images   
Name: Ani
Date: 6/8/2006 5:30:16 AM
Comment:
I have used the code which you have used but still i am unable to dispaly the images.The error i get is
The image “http://localhost:1935/Images.aspx” cannot be displayed, because it contains errors.
Title: retrieving images throgh sql server   
Name: vicky verma
Date: 5/29/2006 2:32:21 AM
Comment:
I have sql server 7.0.is that possible to get images in datagrid ifu have sql 7.0 as ur database
Title: Udapte a row with the image displayed   
Name: Salam
Date: 5/24/2006 4:28:28 PM
Comment:
I forgot to give my mail, here it is salam@altern.org
Title: Udapte a row with the image displayed   
Name: Salam
Date: 5/24/2006 6:34:51 AM
Comment:
Well done, very usefull article. I have a DG with update button. When clicking on the update button, I get the following error :
*******************************
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request
****************************************

Any idea or help would be apprecaited. Thanks in advance
Title: Retriving images from sqlserver and displaying in a datagrid   
Name: suneetha
Date: 5/22/2006 1:33:53 AM
Comment:
Really it is very nice article.
can anybody help me how the same code work in c#(ASP.NET)
if anybody get the result please mail it to
suneetha.chilukuri@gmail.com
Title: funtastic job   
Name: tarun dabral
Date: 5/17/2006 6:49:27 AM
Comment:
its funtastic coding keep it up
Title: Retrieving Images from Sql Server and displaying in a datagrid   
Name: Krupa Shah
Date: 5/5/2006 1:22:44 AM
Comment:
This code was a big help to mee.
I am having problem retrieving all the images and displaying it on the datalist. It only displays one image i.e. 1st in a row.
Could you please reply me on krupabshah@yahoo.com. I will really appreciate that.
Title: problem with data grid   
Name: jm
Date: 4/26/2006 7:23:16 AM
Comment:
hello--the same image is displaying itself over and over again on the grid although I may have different images in there.

i changed the stored procedure associated with this tutorial to the Persons Table from the upload tutorial (not sure why you would make them different)which solved the intial problem of no data showing up however this new problem is a bit perplexing any help would be appreciated.

my email is sodaboy@sodaboy.net
Title: Retrieving Images from SqlServer and displaying in a DataGrid - ASP .NET   
Name: Naveen
Date: 4/1/2006 5:27:31 AM
Comment:
Not very Clear
Title: Displaying Images in GridView   
Name: Rahul
Date: 3/20/2006 1:17:45 AM
Comment:
Thankyou Very Much !! It's a very informative article.
Once again Thankyou..
Title: i am facinf this problem in displaying the data in datagrid   
Name: sridhar
Date: 3/18/2006 3:18:59 AM
Comment:
\
\
\
\
Title: Dynamic Image from Single Fields from Database in a Datagrid   
Name: MM
Date: 3/14/2006 9:28:34 PM
Comment:
Hi
Please tell me how to display Images in Datagrid
eg: i have 15 images in my File location field[in the databse] and i want to show this in a datgrid in 3 columns with 5 rows each
--problem is i need to dynamcally create 3 columns with 5 rows[we can give page size-5] i can do it by getting count and adding 3 rows what will happen i have 33[odd]images or 62[even] or any

pls mail to mathew_mathew@mailcity.com
Title: Ing   
Name: fdeel
Date: 3/13/2006 8:14:26 AM
Comment:
Do you have the C# version of your code
Title: Retrieving Images from Sql Server   
Name: Abu Backar
Date: 3/10/2006 1:34:52 AM
Comment:
thanks for the article, it was a big help for. Masantos Nya Bilay Ed Sika Yun Amin