AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Inserting Images into Database and Display it in GridView through Handler.ashx
Posted by Moderator1 on 7/5/2007 11:31:47 AM Category: ADO.NET
Total Views : 333755
Add to my favorites
Email to friend
  
Introduction
This article explicate the method of inserting images and pictures into SQL Server database table and display it in an Asp.Net GridView control with the help of Handler.aspx.
Description
Have you seen any web application or website without images? No, you cannot. Images played a major role in web application development. Either it’s a static html website or an advanced RAD application, everything is build along with images. If your application is an E-Commerce based or Image Gallery portal, definitely you have to suffer lot on saving the images in different location with different sizes and types. And it’s not an easiest job to manage those unwanted and outdated images to be removed from your file server, then making backup of those images from one server location to another location. So it is clearly time consuming and hectic.
To make your task easier, this article explains you the methods of storing the images into data source. There are many advantages of saving the images into database. The main advantage is easy management of images. You can control the number and size of images stored in your server. You can remove all unnecessary images from the database in a single sql query and you can backup the image data easily. On the other hand, you should be generous of keeping sufficient memory store in your database server.
Inserting Image into Database

To start with, let me explain the SQL Server database table structure we are going to use to insert the image. The table you are going to create to store the image must contain a column of data type IMAGE. This image data type is a Variable-length binary data with a maximum length of 2^31 - 1 (2,147,483,647) bytes. To store the image into this column we are going to convert it into binary string with the help of some IO classes and then insert into the table. For demonstration, we are going to create a table named ImageGallery with four columns in the following structure

Column Name Description Data Type
Img_Id Identity column for Image Id int
Image_Content Store the Image in Binary Format image
Image_Type Store the Image format (i.e. jpeg, gif, png, etc.) varchar
Image_Size Store the Image File Size bigint

After we create table in the database, we can start the coding part.

1. Open your web application in Visual Studio 2005, drag and drop File Upload control and a Button control into the web page.
2. In the code-behind, add the namespace System.IO.

using System.IO;

3. In the Button’s Button1_Click event, write the following code
if (FileUpload1.PostedFile != null
&& FileUpload1.PostedFile.FileName != "")
{

byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
Image.InputStream.Read(myimage, 0, (int)FileUpload1.PostedFile.ContentLength);


SqlConnection myConnection = new SqlConnection(“Your Connection String”);
SqlCommand storeimage = new SqlCommand("INSERT INTO ImageGallery "
+"(Image_Content, Image_Type, Image_Size) "
+" values (@image, @imagetype, @imagesize)", myConnection);
storeimage.Parameters.Add("@image", SqlDbType.Image, myimage.Length).Value = myimage;
storeimage.Parameters.Add("@imagetype", SqlDbType.VarChar, 100).Value
= FileUpload1.PostedFile.ContentType;
storeimage.Parameters.Add("@imagesize", SqlDbType.BigInt, 99999).Value
= FileUpload1.PostedFile.ContentLength;

myConnection.Open();
storeimage.ExecuteNonQuery();
myConnection.Close();
}

To upload the image from any location (your local drive) to the server, we have to use HttpPostedFile object. Point the uploaded file to HttpPostedFile object. Then the InputStream.Read method will read the content of the image by a sequence of bytes from the current stream and advances the position within the stream by the number of bytes it read. So myimage contains the image as binary data. Now we have to pass this data into the SqlCommand object, which will insert it into the database table.

Display the Image in a GridView with Handler.ashx

So far, the article explains the way to insert images into the database. The Image is in the database in binary data format. Retrieving this data in an ASP.NET web page is fairly easy, but displaying it is not as simple. The basic problem is that in order to show an image in an apsx page, you need to add an image tag that links to a separate image file through the src attribute or you need to put an Image control in your page and specify the ImageUrl.

For example:
<asp:Image ID="Image1" runat="server" ImageUrl="YourImageFilePath" />
Unfortunately, this approach will not work if you need to show image data dynamically. Although you can set the ImageUrl attribute in code, you have no way to set the image content programmatically. You could first save the data to an image file on the web server’s hard drive, but that approach would be dramatically slower, wastes space, and raises the possibility of concurrency errors if multiple requests are being served at the same time and they are all trying to write the same file.

In these situations, the solution is to use a separate ASP.NET resource that returns the binary data directly from the database. Here HTTP Handler class comes to center stage.
What is Handler?

An ASP.NET HTTP Handler is a simple class that allows you to process a request and return a response to the browser. Simply we can say that a Handler is responsible for fulfilling requests from the browser. It can handle only one request at a time, which in turn gives high performance. A handler class implements the IHttpHandler interface.

For this article demonstration, we are going to display the image in the GridView control along with the data we stored in the table. Here are the steps required to accomplish this:

1. Create a Handler.ashx file to perform image retrieval. This Handler.ashx page will contain only one method called ProcessRequest. This method will return binary data to the incoming request. In this method, we do normal data retrieval process and return only the Image_Content field as bytes of array.

The sample code follows
public void ProcessRequest (HttpContext context)
{
  SqlConnection myConnection = new SqlConnection(“YourConnectionString”);
  myConnection.Open();
  string sql = "Select Image_Content, Image_Type from ImageGallery where Img_Id=@ImageId";
  SqlCommand cmd = new SqlCommand(sql, myConnection);
  cmd.Parameters.Add("@ImageId", SqlDbType.Int).Value = context.Request.QueryString["id"];
  cmd.Prepare();
  SqlDataReader dr = cmd.ExecuteReader();
  dr.Read();
  context.Response.ContentType = dr["Image_Type"].ToString();
  context.Response.BinaryWrite((byte[])dr["Image_Content"]);
  dr.Close();
  myConnection.Close(); 
 
}

2. Place a GridView control in your aspx page, with one TemplateField column, add an Image control into the TemplateField's ItemTemplate section. Specify the ImageUrl property as
<asp:TemplateField>
 <ItemTemplate>
    <asp:Image ID="Image1" runat="server" ImageUrl='<%#    "Handler.ashx?id=" + Eval("Img_Id")  %>' />
 </ItemTemplate>
</asp:TemplateField>
3. Now we can bind the GridView control to display all the records in the table as follows

GridView1.DataSource = FetchAllImagesInfo();
GridView1.DataBind();

Before you bind the GridView, you should write the FetchAllImagesInfo method to return all the records with their image data from the table and then you have to load the images into the GridView control. The code for FetchAllImagesInfo is

public DataTable FetchAllImagesInfo())
{
  string sql = "Select * from ImageGallery"; 
  SqlDataAdapter da = new SqlDataAdapter(sql, "Your Connection String"); 
  DataTable dt = new DataTable(); 
  da.Fill(dt); 
  return dt;
}

That's it. When you run your project, you can see the images got loaded into the GridView control.

This is a very simple explanation to store images into the data source and to retrieve it back to display in the webpage. You can make the logic even simpler and even elaborate it upto your requirements.

To view our sample application, click here.
Viewer's Comments
Posted by soujanya on 7/19/2007 12:06:19 AM
where is the code for fetchallimagesinfo(); with out that how can we run this program?
 
Posted by sikunj on 7/19/2007 3:34:34 AM
The sample is not working.
 
Posted by sikunj on 7/19/2007 3:35:04 AM
http://www.aspdotnetcodes.com/Inserting_Images_Database_Handler_Sample.aspx Is NOT working
 
Posted by Moderator1 on 7/19/2007 10:48:36 AM
We tested the sample application, it is working fine. The condition to work with our sample is, the image you are going to upload must be less than 5000 Bytes in JPEG, GIF and PNG format. If this condition not met, it will give you an "Invalid File Format" warning message.
 
Posted by lester botch on 7/19/2007 8:37:09 PM
article...inserting images database handler sampler worked fine for me...I was going to get to tackling this project but you beat me to it...nice job
 
Posted by premkumar.r on 7/26/2007 5:44:31 AM
ur code is super.........
 
Posted by asmir on 7/26/2007 3:34:49 PM
I have a problem displaying the images. It inserts it fine and I can display all the information except the image itself. Any suggestions? Thanks
 
Posted by Ganesh Sundar on 7/31/2007 4:05:02 AM
Good Work Done...
 
Posted by Ganesh Sundar on 7/31/2007 4:05:04 AM
Good Work Done...
 
Posted by Ganesh Sundar on 7/31/2007 4:05:05 AM
Good Work Done...
 
Posted by shirley on 8/9/2007 11:23:34 PM
good article...all works fine except my image cant be display.can anyone help pls?
 
Posted by sivakumar on 8/16/2007 6:24:43 AM
hey this article is superb. some guys worte that they could not able to see the images Here i also faced the same problem initially then i overcome it.may be this may help you guys. Dont give space when calling the Handler in the .aspx page Ex:" SyncHandler.ashx?imageid=" + Eval("imageid") " WRONG "SyncHandler.ashx?imageid=" + Eval("imageid") " By removing the spaces in the beggining you try hope this works. i tried like this i got it. BINGO..........................................
 
Posted by lata on 8/25/2007 1:00:10 PM
Good........But I have to display multiple images than how i can?
 
Posted by sivakumar on 8/30/2007 4:43:04 AM
hi how you want to display the images.multiple images means store two images in the db. while displaying also add one more asp template field and call the handlers.ashx. hope this works on.
 
Posted by gfdgfd on 9/26/2007 4:33:09 AM
efsdvfdsv huyrthhtrh0 hytrhtht
 
Posted by Tim Whitley on 10/6/2007 7:50:59 AM
This is a great article. Is there a version written in Visual Basic? Thanks.
 
Posted by sai on 10/10/2007 1:18:48 AM
hi i am getting error as undefined value in the following line DataGrid1.DataSource=FetchAllImagesInfo();
 
Posted by bhaushya on 10/15/2007 4:04:00 AM
this code works superb some peoples cause problems they should pass id correctly and call the grid after the FetchAllImagesInfo() method
 
Posted by sanjay on 10/19/2007 12:16:45 AM
in database id is showing null why. respomce me quickly
 
Posted by saleem on 10/26/2007 7:22:38 AM
code was nice thanks.
 
Posted by Ghislain Tanguay on 11/14/2007 3:59:17 PM
Nicely done man. I was using the poor aspx technique before reading your article to display image inside GridView. With yours, it very, very fast and simple. Tks
 
Posted by Rekansh Patel on 11/17/2007 4:25:48 AM
Thanks for excellent code. this code is work properly download and show image. but this code is working with only .aspx page not with .ascx page. so please anybody know this then give me hint.
 
Posted by Vijay kindre on 11/19/2007 1:31:15 AM
Thanks for this code. UR tech to introduce handle class is good. It works.
 
Posted by Waheed on 11/25/2007 2:30:25 AM
Article is good but it not solved my problem my problem is that: I Want to reterive image from database and will display it on image web control . kindly help me if any body know about it . plz.............................................
 
Posted by Manu Smriti on 11/30/2007 11:36:24 PM
This code is working good but it is retrieving only one image from database. Actually I'm showing images in datalist but getting one image for different products by using this code. Pls help me it's urgent. Thanks
 
Posted by Anagha on 12/1/2007 5:49:30 AM
Very nice article. its very fast and easy. Thank u very much!!
 
Posted by Abi on 12/3/2007 6:13:45 PM
Thanks for the help..
 
Posted by mahua on 12/5/2007 12:58:57 AM
i want to display 4 images,,,2by2..that means 2vertically,,and 2 horizontaly....how can i do it? plz help.....this is urgent......
 
Posted by TAN on 12/6/2007 12:07:30 AM
I have this error on the first part of inserting images into database. -----String or binary data would be truncated. -----The statement has been terminated. if anyone has solution, appreciate if you could drop me a email at tanthiamhuat@yahoo.com
 
Posted by Basheer on 12/10/2007 12:47:22 AM
The data only displayed but the image not display
 
Posted by T H Kishore on 12/18/2007 4:52:55 AM
Hi Here I am used 3 tier.How can i write that Handler.ashx code using 3 tier.Remaining everthing is ok .
 
Posted by hgfh on 12/19/2007 5:19:22 AM
good
 
Posted by Vipin on 12/19/2007 5:35:31 AM
where is the code for fetchallimagesinfo(); with out that how can we run this program?
 
Posted by Vipin on 12/19/2007 5:38:06 AM
where to put the GridView1.DataSource = FetchAllImagesInfo(); GridView1.DataBind();
 
Posted by appu on 12/20/2007 12:11:43 AM
I am getting.Timeout Expired Error. How can I resolve It.
 
Posted by Moderator1 on 12/21/2007 4:12:43 AM
Hi guys, Please close the connection in the ProcessRequest method, else you will get Timeout Expired error. Code needs to be added in ProcessRequest method is myConnection.Close(); myConnection.Dispose(); Thanks.
 
Posted by siri on 12/21/2007 5:46:15 AM
good
 
Posted by ashwani on 1/1/2008 1:54:24 AM
multiple image reterive into database show the image control
 
Posted by Manas on 1/10/2008 4:59:55 AM
This error is happened when i run my application "Prepared statement '(@ImageId int)Select Image_Content from ImageGallery where Img_I' expects parameter @ImageId, which was not supplied."
 
Posted by Joshy M Raj on 1/15/2008 10:09:08 AM
Very Useful Article.Excellent !!!
 
Posted by Arcadian on 1/16/2008 12:44:07 PM
ok.. so what is required in the directive of the handler page? Class? what?
 
Posted by Tu vn on 1/20/2008 9:33:48 PM
thanks.
 
Posted by massu on 1/21/2008 6:36:34 AM
I use this code for insert image in a binary Format but i use it in a Ms Access and in My Project i am not able to get a image in a gridView Control in a ASP.Net Pls Help me Recarding this , Thanks
 
Posted by anil on 2/2/2008 4:39:36 AM
i am using a grid view in my project now i have to Bind this grid with database with the help of class in code bind, then i have apply operations like delete, edit, update or save.Can any body help me on this?
 
Posted by charmout on 2/13/2008 11:38:00 PM
excellent job!!!!!!
 
Posted by ciara on 2/18/2008 8:30:57 PM
i tried to add image in a gridview but it won't work.. could somebody help me..
 
Posted by srinivas on 2/25/2008 8:29:17 AM
this article is very good.
 
Posted by Bruno Seakgano on 2/26/2008 11:40:25 PM
I want to create web. which will store Picture and retrive them . Can you help me out with the sample of coding .
 
Posted by Bruno Seakgano on 2/26/2008 11:40:28 PM
I want to create web. which will store Picture and retrive them . Can you help me out with the sample of coding .
 
Posted by Bruno seakgano on 2/26/2008 11:43:12 PM
I want to create a data base, storing pictures . using ASP. data base SQL. Inserting pictures using ASP and Javascript. Can you help with the coding.
 
Posted by Kanchan on 3/4/2008 5:34:23 AM
Very good Article, facing this problem from very long time, got it now, thank you very much
 
Posted by krishnamoorthy on 3/11/2008 11:47:43 PM
ur code is not undrstandable manner,,,try give better code,,
 
Posted by jyoti on 3/12/2008 1:10:02 AM
hi, this artical is very good and easy.i really solve my problem which i face from long time.thanks
 
Posted by sharat chandra on 3/15/2008 1:28:07 PM
thank you very much.......it worked like a charm to me .facing this problem from very long time, thank you very much
 
Posted by santosh on 3/17/2008 2:17:21 AM
Hi, ur work is very good. my requirement is also same of this article. so, i was used this code as it is. But while execution of code the control is not going to Handler.ashx file. So, that it is unable to displaying image in grid view. please check it and give reply, and tell me what changes i will do. it's very urgent, bye & thanks
 
Posted by santosh on 3/17/2008 2:17:30 AM
Hi, ur work is very good. my requirement is also same of this article. so, i was used this code as it is. But while execution of code the control is not going to Handler.ashx file. So, that it is unable to displaying image in grid view. please check it and give reply, and tell me what changes i will do. it's very urgent, bye & thanks
 
Posted by santosh on 3/17/2008 2:17:32 AM
Hi, ur work is very good. my requirement is also same of this article. so, i was used this code as it is. But while execution of code the control is not going to Handler.ashx file. So, that it is unable to displaying image in grid view. please check it and give reply, and tell me what changes i will do. it's very urgent, bye & thanks
 
Posted by VF on 3/18/2008 1:07:30 AM
V
 
Posted by Kumar on 3/24/2008 9:05:48 AM
Hi i m getting error "Error 6 'ASP.handler_aspx.ProcessRequest(System.Web.HttpContext)': cannot override inherited member '_Default.ProcessRequest(System.Web.HttpContext)' because it is not marked virtual, abstract, or override c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\insert image\61deb9ef\960e228\App_Web_nixznx3f.0.cs 293 " some one pls help
 
Posted by rain on 3/26/2008 8:14:39 AM
where to get the sample coding?
 
Posted by rain on 3/26/2008 8:16:15 AM
where to get the sample coding?
 
Posted by mihir on 3/28/2008 5:52:28 AM
your code is nice . but ihave some problem regarding to that. the image which will be stored in database can not display in the grid view please give me the solution as soon as possible . and also fast. i will wait for ur solution. Regards ------------------------mihir
 
Posted by sanjay on 4/1/2008 3:31:37 AM
I have a problem displaying the images. It inserts it fine and I can display all the information except the image itself is not display plase Any suggestions? Thanks
 
Posted by sanjay on 4/1/2008 3:32:06 AM
I have a problem displaying the images. It inserts it fine and I can display all the information except the image itself. Any suggestions? Thanks
 
Posted by sanjay on 4/1/2008 3:32:10 AM
I have a problem displaying the images. It inserts it fine and I can display all the information except the image itself. Any suggestions? Thanks
 
Posted by utsav on 4/2/2008 7:52:00 AM
Great Article
 
Posted by sowmya on 4/9/2008 2:46:49 AM
I wanted the code in Vb.Also can i get a zip file of this example
 
Posted by Jay on 4/10/2008 12:49:05 PM
Awesome code... just awesome!
 
Posted by ravi madha on 4/22/2008 10:18:26 AM
i does not display. if i just run the handler it says "@image " can any one help please
 
Posted by joohitha on 4/23/2008 6:28:36 AM
hai nice code. But the images are not displaying in gridview. Any suggestions?
 
Posted by varun on 4/23/2008 6:29:48 AM
images are not displaying in gridview
 
Posted by Salemenos on 4/23/2008 7:32:15 AM
Great work! You helped me very much. Many thx...
 
Posted by ttu on 4/25/2008 7:04:28 AM
uut
 
Posted by ttu on 4/25/2008 7:04:28 AM
uut
 
Posted by Srikanth Reddy.M on 4/30/2008 10:45:48 AM
Display to images in Grid view in asp.net Dynamically Changes Dalete and update ...
 
Posted by Arvind kumar on 5/5/2008 2:39:01 AM
i want to store procedure to insert, update, search, data into database.
 
Posted by badariyakkala on 5/6/2008 6:23:06 AM
i am not getting any id in handler page so what to do urgent
 
Posted by sl on 5/13/2008 2:53:40 AM
very useful code , thx :-)
 
Posted by Jaydee on 5/20/2008 8:50:00 PM
Where do you add the FetchAllImagesInfo code?
 
Posted by Mangai on 5/30/2008 4:52:07 AM
Very nice article . EXXXXXXXXXcellent. It would be very useful if i get images displayed in image control. Would u please help me out
 
Posted by Mangai on 5/30/2008 4:52:28 AM
Very nice article . EXXXXXXXXXcellent. It would be very useful if i get images displayed in image control. Would u please help me out
 
Posted by Nish on 5/30/2008 6:08:03 PM
This is great! Unfortunately I am trying to set up the FetchAllImages() but where exactly does this go? Also Do I create an object binding from the gridview? Thanks.
 
Posted by lavanya on 6/2/2008 5:44:41 AM
Hi, I successfully uploaded img. But When i am trying to retrive it is not displaying the Image.Plz try to help out
 
Posted by prasad on 6/4/2008 4:29:07 AM
it is simple .Every Understood simply
 
Posted by Trimurthulu on 6/4/2008 1:45:19 PM
how to display images one by one by using handlers
 
Posted by naveen on 6/6/2008 8:24:34 AM
I find error in 1.cmd.prepare(); 2.where to put GridView1.DataSource = FetchAllImagesInfo(); GridView1.DataBind(); 3. i am not getting the image but iam getting the grid view with no image box.
 
Posted by naveen on 6/6/2008 8:29:46 AM
give us the simplified code
 
Posted by vinay kumar vishwakarma on 6/16/2008 12:49:14 AM
hi i am displaying images into repeater control from database and now changing order of these image with the help of java script on the web page. Now i want save these images into database with changed oreder. how can i achieve this. please help thanks in advance
 
Posted by john on 6/25/2008 2:19:31 PM
image insert in web application form in student personal details how to insert in student photo apllication in asp.net , code behind in vb code send an example this mail thank u
 
Posted by john on 6/25/2008 2:19:38 PM
image insert in web application form in student personal details how to insert in student photo apllication in asp.net , code behind in vb code send an example this mail thank u
 
Posted by john on 6/25/2008 2:19:40 PM
image insert in web application form in student personal details how to insert in student photo apllication in asp.net , code behind in vb code send an example this mail thank u
 
Posted by john on 6/25/2008 2:19:41 PM
image insert in web application form in student personal details how to insert in student photo apllication in asp.net , code behind in vb code send an example this mail thank u
 
Posted by jassar on 6/27/2008 12:59:17 PM
can do this in Vusual basic
 
Posted by jagadeesh on 7/1/2008 1:49:10 AM
Hi ,good work done..but wher to bind gridview where to call public DataTable FetchAllImagesInfo()) as a beginner i need more help from you
 
Posted by Prashant Vedpathak on 7/5/2008 5:21:44 AM
Thank you very much. Just what I needed. Really I learned a nice concept from u. Definately support ur site... Pl keep posting such new concepts...
 
Posted by Kevin on 7/9/2008 11:51:43 AM
It works great until GridView1.DataSource = FetchAllImagesInfo(); where is this placed, in the handler or in defualt.aspx.cs, same question for public DataTable FetchAllImagesInfo()) Thanks guys.
 
Posted by Muhammad Farooq on 7/22/2008 7:46:29 AM
This error is happened when i run my application "Prepared statement '(@ImageId int)Select Image_Content from ImageGallery where Img_I' expects parameter @ImageId, which was not supplied."
 
Posted by Muhammad Farooq on 7/22/2008 8:03:31 AM
"Prepared statement '(@ImageId int)Select Image_Content from ImageGallery where Img_I' expects parameter @ImageId, which was not supplied." what is the solution of this problem ? Please tell me
 
Posted by dharmistha on 7/24/2008 5:37:00 AM
i am also getting same error.. "Prepared statement '(@ImageId int)Select Image_Content from ImageGallery where Img_I' expects parameter @ImageId, which was not supplied." what is the solution of this problem ? Please tell me
 
Posted by Shilpa on 8/1/2008 6:35:09 AM
Excellent and simple approach !!!!!!
 
Posted by chiran on 8/6/2008 4:06:20 PM
superb coding thanx alot
 
Posted by Thirumal on 8/8/2008 1:25:10 AM
gud very niceee if i upload large image it will give error
 
Posted by Didi Michael on 8/13/2008 4:32:49 AM
The solution is excellent and wish most examples are like this, propramming will be heaven on earth. Well done.
 
Posted by Tony on 8/14/2008 2:00:42 AM
This error is happened when i run my application "Prepared statement '(@ImageId int)Select Image_Content from ImageGallery where Img_I' expects parameter @ImageId, which was not supplied." please give me a solution for this..........
 
Posted by Tim on 8/19/2008 10:31:23 AM
THank you. This article assited me to use a handler. My main source of information is the "starter kit" and many of the tricks that are used by the creator of the "start kit" are non-standard. The directive used in this example to bind an image to a handler is the standard auto-generated directive used by VS2005 when the "databinding" smart tag window used to data-bind an image control to a data source. I prefer to use coding style of the "starter kit" and to bind a fileupload control's filebyte
 
Posted by hh on 9/11/2008 5:56:54 AM
i m able to store the images but while retrieving it is not displaying the picture other things are displaying
 
Posted by vinay on 9/11/2008 6:39:27 AM
Thanks Sir..
 
Posted by Shiv on 10/3/2008 5:12:29 AM
Very good article. Thanx
 
Posted by munky on 10/12/2008 6:22:59 PM
i have this code in aspx FormsAuthentication and it will only show the image if you go to the URL of the photo then it works for all the photos. you only need to do it one time on the computer then after that it works but you need to do it for evey new computer to the site ne ideas?????
 
Posted by venkat on 10/16/2008 3:21:57 PM
The code works fine. One of the reason why the image is not displayed on the grid is when there is any error in the .ashx page. Compile using build this page option in VS2005.
 
Posted by Poongodi on 10/17/2008 2:04:29 AM
I am using 3 tier Architecture How can i use this Handler.ashx file...Pls Help Me....
 
Posted by ashwin on 10/17/2008 6:33:11 AM
I am able to save image in database but i'm getting error ------>"Prepared statement '(@ImageId int)Select Image_Content from ImageGallery where Img_I' expects parameter @ImageId, which was not supplied."
 
Posted by sivasree on 10/26/2008 9:36:25 AM
Excellent artical...It worked perfectly...thanks a lot
 
Posted by sivasree on 10/26/2008 9:44:58 AM
mr aswin, change the code in ashx file as shown below... public void ProcessRequest (HttpContext context) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UploadImageConnectionString"].ConnectionString); con.Open(); string sql = "Select Image_Content from ImageGallery where Img_Id=@ImageId"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.Add(&quo
 
Posted by sivasree on 10/26/2008 9:47:33 AM
replace the line in ashx context.Response.ContentType = dr["Image_Type"].ToString(); with context.Response.ContentType = dr["Image_Content"].ToString();
 
Posted by sathish on 10/30/2008 2:18:18 AM
worst,poor,not useful,need to refer some site,bad,take dis into ur head and i expect will change in future
 
Posted by jan on 11/3/2008 1:24:35 AM
how i can display image in gridview using javascript
 
Posted by Pradeep on 11/3/2008 6:51:07 PM
Hi, It works well but I am unable to display the image. except Image everything is fine. Please help me regarding this.
 
Posted by Pradeep on 11/3/2008 7:14:25 PM
Thanks I found this helpful for displaying the image. "replace the line in ashx context.Response.ContentType = dr["Image_Type"].ToString(); with context.Response.ContentType = dr["Image_Content"].ToString();"
 
Posted by ks on 11/11/2008 4:45:34 AM
For those cannot display Image,you can open the table definition and at the property side,then [indenity column] choose [Img_Id].
 
Posted by ks on 11/11/2008 4:50:44 AM
Thanks Pradeep, i follow yr suggestion and it work. :)
 
Posted by ks on 11/11/2008 4:57:53 AM
Those get getting ERROR--->"Prepared statement '(@ImageId int)Select Image_Content from ImageGallery where Img_I' expects parameter @ImageId, which was not supplied." --------------------------------------------- You can try tp open the table definition and at the property side,then [indenity column] choose [Img_Id].
 
Posted by megha jain on 11/15/2008 3:00:47 AM
my code is not running...why i don't know....plz replay me soon
 
Posted by megha jain on 11/15/2008 3:01:56 AM
i want multipal images.
 
Posted by ooi ks on 11/15/2008 11:29:03 PM
which error message u get? megha jain
 
Posted by cagatay on 11/17/2008 10:05:25 AM
can someone tell me why the images are not displaying no matter what i did. please email me if you know. i did everything ok its just not displaying. its not throwing any errors or warnings or anything just an x is displaying on each gridview row my email is taylanozgur78@hotmail.com
 
Posted by taylan on 11/18/2008 7:53:59 AM
actually i solved it by inserting them in db and retreiving them back to the grid
 
Posted by Banjo on 11/27/2008 6:06:24 AM
Hi, It works well but I am unable to display the image. except Image everything is fine. Please help me regarding this.
 
Posted by daniel on 12/6/2008 11:12:01 PM
excellent code, thanks man, if you have other articles please tell us ...
 
Posted by IrianGald on 12/23/2008 12:02:46 PM
My code is runnin' so cool!!! Thanx
 
Posted by mahdi on 12/26/2008 12:58:17 AM
hi, I can not Create a Handler.ashx file in vb.net or C# please tell me how to create by more detail. tanks
 
Posted by Amna on 1/1/2009 1:15:09 AM
Hi I want to insert images in database (SQL Server 2005) Through VB.NET (Visula Studio 2005) I m using Insert Query for this Purpose Means Somethink Like Insert into EmployeeTable(EmployeeID,EmployeeName,EmployeeAddrress,EmloyeeContact#,EmployeeImage) Values (EmployeeID,Name,Address,Contact,Image) But Here is a problem image data is Byte Type and it is not concatenated in the Query Becoz Query Develops a string this is the problem And Can U please tell me the Proper way to Store and r
 
Posted by Ums on 1/2/2009 4:02:20 AM
Hi amna, Instead of going through insert query, you just try with stored procedures..!
 
Posted by Ums on 1/2/2009 4:04:08 AM
Hi mahdi, Just go to solution explorer, and add new item from there you select Generic Handler that is the handler file...! Hope you got clear now..!
 
Posted by Ramesh on 1/5/2009 3:37:24 AM
your code is not work properly. Because its fetch runtime error
 
Posted by Suresh on 1/5/2009 6:21:47 AM
Hi ...! i want a solution.. how can we insert an image in a database.....by using java technology....here given in asp.net... so plz anyone of u tell me.....
 
Posted by $wank on 1/6/2009 9:06:20 AM
I've got the complete source corrected if anyone needs it
 
Posted by shabi on 1/8/2009 1:33:20 AM
code working fine.but the main issue image is not displaying.
 
Posted by Avijit Patra on 1/8/2009 3:40:39 AM
I have a problem displaying the images. It inserts it fine and I can display all the information except the image itself. Any suggestions? Thanks for the code.
 
Posted by Avijit Patra on 1/8/2009 3:42:56 AM
Hi $wank i want the complete code. can u help me?
 
Posted by Avijit Patra on 1/8/2009 3:54:43 AM
Thanx Pradeep for your valuable suggesstions.
 
Posted by Abhisek on 1/8/2009 4:37:57 AM
Excellent work
 
Posted by shakeer on 1/8/2009 11:30:08 PM
Plz send me the code how to display image in Datagrid through database..Plz send me Fast Anybody syedshakeer@rediffmail.com
 
Posted by shakeer on 1/9/2009 12:24:37 AM
Plz send me correct code for displying image..
 
Posted by Caitriona McDonald on 1/12/2009 10:56:07 AM
Hi, I have a folder with all our Staff images that are saved by their staff number. I have created a little C# webpart to display the details of all new employees with Gridview in Visual Studio 2008. I can bring in all their information but can't get their image to display. Do I have to copy all images into a database and then display or should I be able to call the images from the folder? Thanks, Cacmd
 
Posted by Name on 1/15/2009 1:13:25 PM
Thank you so much. After changing: "context.Response.ContentType = dr["Image_Type"].ToString();" for "context.Response.ContentType = dr["Image_Content"].ToString();" it worked just perfect :)
 
Posted by Prabhat on 1/21/2009 12:27:34 AM
Very good Artical, thank u very much....
 
Posted by Zubair on 1/21/2009 7:41:10 AM
Gr8 man Oesome
 
Posted by Pawan on 1/22/2009 4:44:03 AM
gud codes
 
Posted by amit on 1/27/2009 4:39:41 AM
i successfully save image in database but it is not displaying in grid . it is displaying following error what is the solution of this problem which is occuring in handler.ashx The parameterized query '(@ImageId int) Select ImageContent from ImageGallery where Image' expects the parameter '@ImageId', which was not supplied. Statement(s) could not be prepared
 
Posted by amit on 1/27/2009 4:40:14 AM
i successfully save image in database but it is not displaying in grid . it is displaying following error what is the solution of this problem which is occuring in handler.ashx The parameterized query '(@ImageId int) Select ImageContent from ImageGallery where Image' expects the parameter '@ImageId', which was not supplied. Statement(s) could not be prepared
 
Posted by David on 1/27/2009 5:02:16 PM
Excellent solution, worked like a charm for me.
 
Posted by Serhat on 1/31/2009 5:57:02 AM
Yes, it works. However it is not complete. Think of the following simple senario. You have a products table and you have seperate images table. You want to display images in the same gridview as products. Some products have images and some don't. Using an sql statement which joins the two table only pulls out those with the images and products which is not related to an image (products with no image) is left behind.
 
Posted by satya on 1/31/2009 6:13:57 AM
I am not getting Images from database Yaar.
 
Posted by mohammed syam on 2/1/2009 6:35:31 AM
hi thank you 1)- the store of the image in sql table work fine , but the display in a grid dosent work. 2)- just a note its a dead end when we store the image itself in the table it is better to store the url (path) only. you may give us a project like that . thank you agian
 
Posted by shamsheera on 2/4/2009 4:56:26 AM
I successfully store images in database but i am not getting images from database. Plz send me correct code. Thanks.
 
Posted by Jit on 2/5/2009 4:44:23 AM
Hi It is working and displaying in IE6 fine but it is not working with IE 7..can any one help
 
Posted by Joe on 2/6/2009 2:04:52 PM
Do you have the files in VB? Thanks
 
Posted by Nagalakshmi on 2/19/2009 5:27:42 AM
Very clear explanation! Understandable to freshers also. Very nice and Thanks a lot
 
Posted by karthi on 2/20/2009 6:50:14 AM
where i can put these things gridview1.datasource =fetchallimages, gridview.databind();
 
Posted by karthi on 2/20/2009 6:51:09 AM
when i want to call it pls help me urgent
 
Posted by M.priya on 2/22/2009 9:27:55 PM
I wanted the code in Vb.Also can i get a zip file of this example and c# using .net coding also
 
Posted by Shubham on 2/24/2009 12:48:28 PM
On Statement- storeimage.ExecuteNonQuery(); It is giving an error [SqlException (0x80131904): String or binary data would be truncated. Please Solve..
 
Posted by anand on 3/5/2009 1:37:53 AM
how can i assign image url directly to image control with out useing gridview
 
Posted by Prashant on 3/6/2009 3:28:09 AM
Can I get in VB code if possible.
 
Posted by pradeep on 3/9/2009 6:04:38 AM
i got the error like this how can i solve this error System.Data.SqlClient.SqlException: Parameterized Query '(@ImageId int)Select Image_Content from ImageGallery where Img_I' expects parameter @ImageId, which was not supplied.
 
Posted by AJAY on 3/15/2009 11:27:46 PM
this code is for the insertion of the image into the data base if we want to take image as a password what will be the logic about that
 
Posted by ravi singh on 3/20/2009 2:57:43 AM
Great Post , thanks, only u need to change in sql from handler "string sql = "Select Image_Type, Image_Content from ImageGallery where Img_Id=@ImageId"; " Thanks Once Again
 
Posted by misza on 3/21/2009 7:36:38 PM
Great Post , but... I did everything what u write i'v done all changes but images still wan't come out . Can somebody send me working file to compare . My email misza.pliki@gmail.com
 
Posted by new programmer on 3/29/2009 4:25:28 PM
I am totally totally confused.... i hve seen many articles and implemented them as well practically but all of them are worth less including this one... MY dude.... i hve followed every step that mention in the articles and plus in the comments, even than i m unable to call image in the grid view... check out urself before publishing such articles.. There is NO IMAGE called in the grid view in RUN TIME.. PLZZZZZ Make it solve and than publish the NEW article regarding same problem.... sorry for
 
Posted by new programmer on 3/29/2009 4:31:14 PM
if some one has running copy of this article plzzzzzzzzz forward it to my ID which is.... salman_programmer1@hotmail.com waiting for the replay thanks in ADVANCE
 
Posted by Aman Juneja on 4/6/2009 6:45:18 AM
i m getting problem with this code, i have done same code same as mentioned above but images are still not displaying could you plz help me about how to display images in grid view from database. If someone have any idea then plzzzzzzzz send me code on aman_juneja@hotmail.com. Thanks
 
Posted by demin Hu on 4/6/2009 4:26:22 PM
Great,it works if you make a little changes in Handler.ashx. change sql string as the following; string sql = "Select Image_Type, Image_Content from ImageGallery where Img_Id=@ImageId";
 
Posted by Abdulla on 4/13/2009 11:45:47 PM
how can i insert into database desktop pictures?
 
Posted by Ratheesh.r on 4/14/2009 12:57:44 AM
I got this error Prepared statement '(@ImageId int)Select Image_Content, Image_Type from ImageGallery' expects parameter @ImageId, which was not supplied. Statement(s) could not be prepared. please give me a solution urjently
 
Posted by dollarsai on 4/14/2009 2:08:21 AM
Good article........It just worked in 1st shot..... U rock man!!!
 
Posted by Pep on 4/29/2009 7:08:07 AM
hi all, I too have the same problem.Not able to display the images on a grid view but I am able to insert the images in to the DB.can anybody suggest why I am not able to display the images pepcoder@live.com
 
Posted by Jugal Kishore on 5/1/2009 12:52:21 AM
Dear Sir, When I tried to use this code the images inserted into database perfectly but when I used ashx file it gives me error says sqlDbType does not exist in the current context . Please help me.
 
Posted by Alex on 5/1/2009 9:19:17 AM
hey sir.. you just saved me loads of hours of work :D:D.. great work and great working .. also one of the few tutorials i saw that i know what you where doing .. A+++
 
Posted by Shiva on 5/2/2009 3:24:53 PM
Thnx Dude........... wonderful Article...........Great Job
 
Posted by Viju on 5/4/2009 5:00:55 AM
Can anybody send a working copy of the code mentioned below in my my mailid : pepcoder@live.com. I am able to insert the images but not able to display...
 
Posted by Pep on 5/5/2009 5:12:44 AM
Hai All, I have found the solution finally why the images are not displaying.. keep.. both your handler(filename.ashx) and the .aspx (filename.aspx) file in the same folder.(specify the path of the handler file otherwise when u specify the ImageUrl path... eg: if both are in the same folder: ImageUrl='<%# "ShowImage.ashx?id=" + Eval("pic_id") %>' /> if in sep folder. "ImageUrl='<%# "~/FolderName/ShowImage.ashx?id=" + Eval("pic_id")
 
Posted by bhoomi on 5/8/2009 6:47:05 AM
i got the error like this how can i solve this error System.Data.SqlClient.SqlException: Parameterized Query '(@ImageId int)Select Image_Content from ImageGallery where Img_I' expects parameter @ImageId, which was not supplied.
 
Posted by Md. Azharuddin on 5/8/2009 3:23:36 PM
I have a problem displaying the images. It inserts it fine and I can display all the information except the image itself. Any suggestions? Thanks
 
Posted by aryan on 5/8/2009 7:41:32 PM
Thanks for the great article. Is there a way to do something like img.imageUrl = "Handler.ashx?id=1"; and send a request to the ashx file in the background code?
 
Posted by Morad on 5/9/2009 5:54:24 AM
i got this error and i can't understand why Conversion from string "Handler1.ashx?id=" to type 'Double' is not valid. plz help me
 
Posted by Morad on 5/9/2009 10:35:52 AM
thaaaaaaaaaaanx Now its working fine i fixed this problem
 
Posted by Umang on 5/21/2009 4:42:47 AM
hey code is good but images are not displayed is it complasary that v have to seprate image type in database or take image title(ex. abc.jpg) as field.
 
Posted by rahil on 5/23/2009 11:41:40 AM
thanks will try it
 
Posted by Jennifer on 6/3/2009 4:16:24 PM
Works well for datagrid. Let's say I have an imagebutton, and I want that ImageButton to be populated with a returned image from the database, then I want just an image to have a different image. Any code or direction on how to bind it to an Image or ImageButton instead of a GridView?
 
Posted by Cindie on 6/4/2009 3:32:55 PM
Anyone have an idea of how to bypass the handler when deleting row with grdImages_RowDeleting?
 
Posted by sikha on 6/10/2009 11:27:51 PM
hi, i want to insert an image in a database.i used linkedsource in my database. i m waitting 4 ur reply. thanks
 
Posted by shiv on 6/13/2009 5:30:03 AM
i have a image database. but i want to know how to displaey image to datagrid. using drop dwon list. thanx
 
Posted by Dinu on 6/16/2009 8:32:45 PM
Thanks a lot...I searched a lot for a good article..finally i got it.its simple with a very good description.my code is working properly..once again thanx a lot..
 
Posted by Jeyaganesh on 6/29/2009 2:42:28 AM
How i can display image in gridview....
 
Posted by Jeyaganesh on 6/29/2009 2:44:23 AM
This is fantastic artice.. Thanks & Thanks//
 
Posted by Jeyaganesh on 6/29/2009 3:11:29 AM
hi sikunj now this page is working.. find out http://www.aspdotnetcodes.com/Inserting_Images_Database_Handler_Sample.aspx
 
Posted by anand sharma on 7/6/2009 2:32:34 AM
how can i make a call to handler at runtime
 
Posted by ramaniranjan das on 7/8/2009 8:38:15 AM
how to create Handler.ashx file? plz mail me as soon as possible Thank u
 
Posted by anjana on 7/10/2009 11:52:24 PM
i got an error failed to convert a string to int 64
 
Posted by anjana on 7/11/2009 12:49:12 AM
plz reply me how can i solve the above problem
 
Posted by vinod on 7/24/2009 6:00:08 AM
how to insert ,update ,delete data from Sql server using c sharp in asp.net? how to display those data through datagrid?
 
Posted by tmaha on 8/3/2009 6:45:03 AM
I want this code in VB if it's possible please to
 
Posted by tmaha on 8/3/2009 6:45:18 AM
I want this code in VB if it's possible please to
 
Posted by tmaha on 8/3/2009 6:46:28 AM
I want this code in VB if it's possible please to thank you very much
 
Posted by Himesh on 8/8/2009 9:18:08 AM
Image does not working......... image cant able to see.... otherwise all working
 
Posted by edgecrosser on 8/20/2009 11:11:07 PM
Hello! I'm also having an error like this: "Conversion from string "Handler.ashx?ID=" to type 'Double' is not valid." Please help me :(
 
Posted by wael on 8/23/2009 5:41:42 AM
this code is very helpful but i need to display 3 images in the same row and bind it to the gridview can anyone help me thanks in advance my email is waelwehbe585@hotmail.com for any example
 
Posted by susmitha on 8/26/2009 8:18:14 AM
hi i am getting null value in handler.aspx string imageid = context.Request.QueryString["ImID"]; and i have one row in my ddb please help me
 
Posted by Abiy on 8/28/2009 2:01:37 PM
thanks guys - superb code. You saved me a lot.
 
Posted by sana on 9/2/2009 6:21:35 AM
hello i want to creat a script for my site which will be metremonial script and i was looking for just this kind of script for uploading imgs and retrive it in asp.net , thanks man it works for me
 
Posted by AC on 9/11/2009 2:25:59 AM
good job.
 
Posted by Shashank on 9/16/2009 3:05:35 AM
Hello, the code is working fine for me. But I am facing a problem now. I have not set identity for column Img_Id. I am inserting Img_Id manually and while retrieving I am providing the Img_Id in a textbox. Now when I provide the same Img_Id for 2 different images, "while displaying it shows the first image for both the records." Whereas rest of the columns remains the same...Please provide some suggestions.
 
Posted by pravin mahit on 9/23/2009 1:39:07 AM
its very good & it is working properly thank you
 
Posted by abhilash on 9/28/2009 10:14:02 PM
hey man ur awsome i was trying to upload imgaes from 3days and finally got from ur example.................thank qqqqqqqqqq
 
Posted by karthik on 9/30/2009 5:13:58 AM
this is working fine,intially i faced 2 problems, one is "while converting int"->i solved this one by changing id as varchar, another one image not displyed ->in code i had mentioned handler.ashx instead of handler1.ashx finally it is working
 
Posted by Rocky on 10/5/2009 5:52:34 AM
I am getting error Conversion from string "~/Handler1.ashx?id=" to type 'Double' is not valid. Please Help me..
 
Posted by Mio on 10/18/2009 10:37:50 AM
Yes its good. I used VB. My only problem was conversion of datatypes. Just like Rocky. Now I have to find a way to resize big pictures.
 
Posted by mathieu cupryk on 10/27/2009 2:16:55 AM
Insert images into the database. I am in the same boar as Rekansh Patel Does anyone have a wokring version with ascx. I appreciate it. mathieu_cupryk@hotmail.com
 
Posted by Shannon on 12/1/2009 2:58:23 PM
I see lots of request of the code in VB, however, I don't see it posted. How can I get the code in VB.
 
Posted by Anish on 12/2/2009 1:16:14 PM
Everything Expect Image is showing,more over your sample link to upload image is not working i tried with files of less than 1000bytes saying invalid format
 
Posted by mamatha jayagiri on 12/2/2009 11:08:05 PM
Hello.. I tried this code .. still iam unable to display the image. I dont know what is the reason. Can u please help me. My tables in SQLserver Database is Imageid-int datatype Image1 - image datatype With the help of imageid iam trying to display image in gridview.. pls help me..
 
Posted by asp.net newbie on 12/6/2009 6:26:06 AM
If you get the error : error Conversion from string "~/Handler1.ashx?id=" to type 'Double' is not valid you have to change the imageurl to ...Eval("Img_Id").toString()
 
Posted by vahid on 12/13/2009 1:58:53 AM
hello friends. if your handler file dont work and dont show your pictures in gridview,because you mast convert to Array binary data that you fetched from db. this code write with linq. <%@ WebHandler Language="C#" Class="imgHandler" %> using System; using System.Web; using System.Linq; using System.Data.Linq; using System.Text; using System.IO; using System.Drawing; using System.Drawing.Imaging; public class imgHandler : IHttpHandler { TciTowers
 
Posted by vahid on 12/13/2009 2:02:07 AM
var qupic = (from f in objDataContext.MastPictures where f.pId ==Convert.ToInt32(context.Request.QueryString["id"]) select f).First(); context.Response.ContentType = "image/gif"; context.Response.BinaryWrite((byte[])qupic.Pic.ToArray());
 
Posted by Paul on 12/14/2009 7:05:58 PM
vahid - I am interested in your code using linq, what followed your post after { TciTowers .... ??
 
Posted by mojtaba on 12/19/2009 9:17:12 AM
tanx it is good
 
Posted by devasena on 12/21/2009 4:10:35 AM
coding for how to add an uploaded image using VB.NET to SQL server database
 
Posted by Ashraf Morad on 12/28/2009 12:47:16 AM
Great work. Thank you so much
 
Posted by Chris on 12/30/2009 6:07:29 PM
Good job mate, just got it to work!
 
Posted by saba on 1/6/2010 1:53:12 AM
code is gud but im not getting image instead System.Byte[] is appearing there
 
Posted by Moniruzzaman on 1/21/2010 9:31:16 AM
code is good and i have retrieve image from sql server successfully.Thanks......
 
Posted by mona on 1/21/2010 12:28:30 PM
i have implemented logic which you described above in my project but there is a problem that for every field in grid view only one image saved on first row of table is displayed ,nevertheless there are other images saved in database but they are not displayed ,please tell me what problem could be there
 
Posted by hamideh on 1/28/2010 7:25:21 AM
hi,my picture do'nt display in the gridview . can I send the source code . please help me
 
Posted by prasath on 2/2/2010 5:42:33 AM
please send one example of all controls in asp.net (c# coding)
 
Posted by Nitin Sharma on 2/10/2010 3:37:42 AM
Lovely article
 
Posted by good work on 2/13/2010 1:07:49 AM
great work . thank u very much
 
Posted by Mansoor Bari on 2/16/2010 4:54:56 AM
Please send me this code in VB.NET
 
Posted by sharath chandra on 2/18/2010 1:45:51 AM
how to get the value of ID in context.Request.QueryString["id"] from .aspx.cs page to Handler,.ashx pleasereply meto my mail or her
 
Posted by Fco on 3/6/2010 10:53:23 PM
Could you help me with the VB.NET code?? great job thank you!!!
 
Posted by chaitanya on 3/16/2010 11:47:28 PM
Good job,But i want to show all images having binary form presented in database in gridview.This code is showing only perticular imge. i am very appricitiate you if u help me.
 
Posted by Sakthi on 3/18/2010 5:04:43 AM
GOOD WORK ................
 
Posted by sreekanth on 3/19/2010 9:30:30 AM
Good Work ..........
 
Posted by shrek on 3/19/2010 9:59:04 AM
great job thank you!!!
 
Posted by nagamani on 3/23/2010 2:53:54 AM
how can i retrive the images through database in asp.net
 
Posted by ISHRAR KHAN on 3/23/2010 10:55:28 PM
This code is well but here image_id r not supply,so when we run this code all recard r shown but picture r not show. how Image_id automatically taken by ashx pages till we not supply. so above r not complete solution
 
Posted by Saj on 3/26/2010 12:37:44 PM
thank you sooo much mate, ur 1 line of code saved me alot of hassel man, beautiful work mate thank you so much
 
Posted by Saj on 3/26/2010 12:38:57 PM
any chance you could a simple code for a feed back form to be sent to specific email address in asp.net????
 
Posted by Chirdeep on 4/20/2010 2:43:54 PM
where to put the GridView1.DataSource = FetchAllImagesInfo(); GridView1.DataBind();
 
Posted by sharada on 4/22/2010 1:02:19 PM
Ur article is working properly.I'm able to insert pictures into table But i'm unable to see the images in gridview. Please suggest. Reply awaiting. Regards Sharada
 
Posted by sukhminder on 4/28/2010 3:01:07 PM
Excellent code but with slight modifications. no need to give GridView1.DataSource = FetchAllImagesInfo(); GridView1.DataBind(); public DataTable FetchAllImagesInfo()) { string sql = "Select * from ImageGallery"; SqlDataAdapter da = new SqlDataAdapter(sql, "Your Connection String"); DataTable dt = new DataTable(); da.Fill(dt); return dt; } and images will be well displayed
 
Posted by rathan on 5/5/2010 2:54:05 AM
gr8 work.nice and simple code.
 
Posted by Deepali on 5/10/2010 2:25:07 AM
I can't see image,got error-"Failed to convert parameter value from a String to a Int32". pls,give me solution it's urgent,thanks.
 
Posted by Hardik Shah on 5/10/2010 6:10:09 AM
I want to apply images into access database and want it to display into gridview when the page is displayed on webpage. Pls help me to solve this problem.
 
Posted by Arun Robert on 5/16/2010 3:05:50 AM
how to enter data in sqlserver and displaying in gridview with vb code
 
Posted by poonam on 8/27/2010 2:02:08 AM
data is display but image is not display in grid view
 
Posted by surender on 8/27/2010 4:11:35 AM
asp.net video
 
Posted by Nilesh Mohite on 9/15/2010 1:44:28 PM
Thanks ! God bless you !
 
Posted by dev on 10/2/2010 5:46:32 AM
thaks but i have a proble
 
Posted by Anirban on 10/29/2010 12:36:47 PM
in this line cmd.Parameters.Add("@ImageId", SqlDbType.Int).Value = context.Request.QueryString["id"]; display a message ('SqlDbType' does not exist in the current context) what i do...reply
 
Posted by rajan naidu on 11/1/2010 7:40:50 AM
i haven't tried it yet but i got some ideas thank u and continue the same
 
Posted by ian on 11/25/2010 11:10:31 AM
storeimage.Parameters.Add("@image", SqlDbType.Image, myimage.Length).Value = myimage; The name 'SqlDbType' does not exist in the current context S.O.S
 
Posted by DigitalMan on 12/1/2010 8:54:37 PM
I used SQL 2008 and varbinary (max) instead of the older image type. Here is the create table I used: USE [MyDatabase] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[ImageGallery]( [Img_Id] [int] IDENTITY(1,1) NOT NULL, [Image_Content] [varbinary](max) NULL, [Image_Type] [varchar](50) NULL, [Image_Size] [bigint] NULL, CONSTRAINT [PK_ImageGallery] PRIMARY KEY CLUSTERED ( [Img_Id] ASC )WITH (PAD_INDEX = OFF, STAT
 
Posted by olen on 12/12/2010 12:48:49 PM
Thankyou very much, I have been trying to figure out how to display images for a long time. It works!
 
Posted by imad on 1/1/2011 8:22:11 AM
Bravo!
 
Posted by star on 1/17/2011 11:25:50 PM
hi for me image is not displaying in the grid view. can you help me?
 
Posted by saif khan on 2/19/2011 9:18:57 PM
No wonder why did you get a so long comments list. You are rock man. saif from Pakistan.
 
Posted by aelface on 2/21/2011 8:59:17 PM
SqlDataReader dr = cmd.ExecuteReader(); Failed to convert parameter value from a String to a Int32.
 
Posted by aelface on 2/21/2011 8:59:59 PM
PLEASE HELP ME !!!
 
Posted by asdf on 3/15/2011 7:38:20 PM
Generally good guide, but got stuck when I didn't know where to put this piece of code: GridView1.DataSource = FetchAllImagesInfo(); GridView1.DataBind();
 
Posted by Rizwan on 3/28/2011 11:27:44 AM
Nice Article dude .
 
Posted by NqHung on 4/8/2011 4:37:15 PM
hi, good article! it work. But i want to display a document content instead of image (e.g i want upload a .doc file then display the content to the page) how can i modify this example to do that?
 
Posted by neeraj on 4/24/2011 11:22:44 PM
it is awesome
 
Posted by dev1 on 7/1/2011 6:55:13 AM
hi, good article. One question: i have emp details screen and below that emp list grid, when i select photo for emp for first time on detail screen and save it to database, and refreshes grid view by again quering on database, it shows newly added photo, but when i again select that row from grid and add new photo for emp the grid view does not display that new image,though its saved in database. Can you please help me to solve this problem, Thanks in advance.
 
Posted by Syed on 7/8/2011 1:41:11 AM
Use 'System.Data.SqlDbType' instead of 'SqlDbType'. It Work Well..
 
Posted by Carlos on 8/2/2011 1:01:26 PM
Hi all, Why is showing all the table fields? Img_Id, Image_Content , Image_Type, Image_Size i just need to show image_content any help?
 
Posted by waseem sahi on 10/24/2011 10:38:11 AM
hi to all i am working with this project but i dont know that where i have to place the code below public DataTable FetchAllImagesInfo()) { string sql = "Select * from ImageGallery"; SqlDataAdapter da = new SqlDataAdapter(sql, "Your Connection String"); DataTable dt = new DataTable(); da.Fill(dt); return dt; } and GridView1.DataSource = FetchAllImagesInfo(); GridView1.DataBind(); plz tell me someone on my id
 
Posted by Peter on 11/4/2011 12:27:56 AM
If you get an error along the lines "asp.net String or binary data would be truncated" it because this stupid cunt didn't specify how big to make the Image_Type column, don't leave it as varchar
 
Posted by lorin on 11/15/2011 4:35:27 PM
hi to all i am working with this project but i dont know that where i have to place the code below public DataTable FetchAllImagesInfo()) { string sql = "Select * from ImageGallery"; SqlDataAdapter da = new SqlDataAdapter(sql, "Your Connection String"); DataTable dt = new DataTable(); da.Fill(dt); return dt; } and GridView1.DataSource = FetchAllImagesInfo(); GridView1.DataBind(); plz tell me someone on my id
 
Posted by Ashok on 12/13/2011 4:12:06 AM
HI SIR, I DIDNT GET IMAGE IN GRIDVIEW.AND THERE IS NO ERROR
 
Posted by abhishek singh on 2/28/2012 12:56:05 PM
Thanx it is working gud
 
Posted by iamkp on 2/29/2012 1:41:12 PM
thank u bro... :D
 
Posted by akshay on 3/19/2012 5:10:07 AM
Nice code,wrkd excellently with gridview ^_^ jst want to knw how to display img frm db w/o gridview,rply @:akshay022s@gmail.com
 
Posted by joe on 4/8/2012 11:17:14 AM
what a code.......its awesome........thanks for the code..you guys are rock
 
Posted by Alex on 6/6/2012 11:16:47 AM
Excellent. Made very clear and simple.
 
Posted by Tessa on 6/14/2012 2:50:52 PM
Hello, may i know how to not displaying the image id and the description? I just want to display the image. Any solution for this? Thanks =)
 
Posted by Mayura on 7/5/2012 8:54:57 PM
Hey Image is not displaying in the grid view. please help me
 
Posted by df on 11/6/2012 1:31:41 AM
Image was not displayed for using above code
 
Posted by df on 11/6/2012 1:49:33 AM
sample is working good. but i.m try to run this project its not display the images
 
Posted by tonmoy on 1/11/2013 10:27:11 PM
hey, can any one tell me the code to display the image in image control box from database.
 
Posted by prakash on 2/18/2013 3:48:53 AM
how to display the image in gridview.. i didn't understand your concept.. the images are stored into database as per your coding when i click save button.. but, how to display the images..
 
Posted by prakash on 2/18/2013 6:10:32 AM
i've getting the same image (i.e sored at first row in the database) only display in the gridview. and how many images stored in database that much time to be displayed in the same first image... i want to displaying all images to be stored in database.. plz, help me... thanks a lot..
 
Posted by Sradhanjali on 3/17/2013 11:53:01 PM
hey,can any one please help me how to export the data including image i.e on the datalist to pdf file on click of a button control
 
Posted by amit on 3/28/2013 1:32:38 AM
how can i add image in sql server
 
Posted by wattdll on 4/12/2013 12:58:01 PM
My images are not displaying either but the rest of the grid data is there. Can anyone please help me?
 
Posted by Ankit patel on 8/30/2013 5:43:49 AM
Thank you for this code.. it helps lot..
 
Posted by Bhavna on 10/15/2013 5:37:51 AM
my images are still not displayed but it gets successfully uploaded. Please help.
 
Posted by jdn on 11/16/2013 7:09:28 AM
Very nice approach. Did you have it using a passed Byte variable (as the image already readed) instead of reading from a database? Also, have you a VB version?
 
Posted by vinay singh on 5/10/2014 1:26:30 AM
i m always getting a broken image
 
Posted by Sneid on 8/14/2014 11:34:13 AM
Nice work - thanks for sharing your code..... would love to see some extended manipulations with respect to the image - such as producing a thumbnail view and an enlarged view...
 
 Rating & Comments
A word 'Excellent' means lot to the author of this article. You can give comments about this article but not the author.
Rate this Article:
Name:
Email Id:  
We never display your email id anywhere.
Comment/Question: Max. 500 letters
Ninety minus Three Equals To
 
Sponsored by
Oracle Magazine
Simply SQL - Free 111 Page Preview!
Washington Technology