The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: Inserting And Reading Image To/From Database in ASP.NET (Web Application) in Image Control
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Girish SharmaPosted Jan 2, 2018, 2:09 AM
FileStream fs = new FileStream(FileUpload1.PostedFile.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); my image path is showing null in fs variable. and goes to catch () directly......give me some suggestion to solve it
Nilesh ManePosted May 22, 2016, 2:58 AM
errors - how to solve - Access to the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\download.jpg' is denied.
RawatPosted Feb 29, 2016, 6:29 AM
you are niit student
ehsan bPosted Jan 7, 2016, 6:55 AM
sorry I cant download the codes
ehsan bPosted Jan 7, 2016, 6:37 AM
thank you for helping
kamanzi ernestPosted Aug 14, 2015, 5:08 AM
all code is okay but when i trying to retrieve image,others displayed image not
Ashok KuamrPosted Jan 15, 2014, 8:24 AM
Inserting And Reading Image To/From Database in ASP.NET (Web Application) in Image Control in here when i retrive image then one error come from Handler.ashx page,error is "ArgumentOutOfRangeException was unhandledby user code" Specified argument was out of the range of valid values. Parameter name: offset ...........................................what is this?????????
ahmed hassanPosted Nov 10, 2013, 7:40 AM
using previous code
ahmed hassanPosted Nov 10, 2013, 7:39 AM
how can i add .swf file and retrieve it into web page
Vishal GilbilePosted Mar 7, 2013, 7:57 AM
Hello Rajesh, I've gone through your code the way of retrieving the image file from the database is perfect but with constraint to that your dropdownlist2.Text provides you the id(in your case cnumber) of the database table. What i can suggest you in this case is that the above code of inserting the image in the table is written in .Net 2.0 framework, try to google how to insert a image file in DB in higher version of .net framework. But the way of retrieving the image file would be same. Hope that helps you.
rajesh barnalaPosted Mar 7, 2013, 7:14 AM
see once my code i am not getting out put plssssssssssssssss <%@ WebHandler Language="C#" Class="Handler" %> using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; using System.Data.SqlClient; public class Handler : IHttpHandler { public void ProcessRequest(HttpContext context) { if (context.Request.QueryString["id"] != null) { // context.Response.Write(context.Request.QueryString["id"]); SqlConnection con = new SqlConnection("uid=sa;pwd=admin123;database=grpact;server=ADMIN-PC"); con.Open(); SqlCommand cmd = new SqlCommand("Select images from image where cnumber=@id", con); cmd.Parameters.AddWithValue("@id", context.Request.QueryString["id"].ToString()); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); context.Response.BinaryWrite((byte[])dr["images"]); dr.Close(); con.Close(); } else { context.Response.Write("No Image Found"); } } public bool IsReusable { get { return false; } } } at c# protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("uid=sa;pwd=admin123;database=grpact;server=ADMIN-PC"); con.Open(); SqlCommand cmd = new SqlCommand("Select * from image where cnumber=@id", con); cmd.Parameters.AddWithValue("@id", DropDownList2.Text); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { Image1.ImageUrl = "~/Handler.ashx?id=" + DropDownList2.Text; } con.Close(); }
preetpal kapoorPosted Feb 2, 2013, 6:11 AM
HI, I was trying the above given code .. its running fine but while retrieving the image from DB no image is shown .. Please help me in this
raghu gowdaPosted Jan 14, 2013, 2:56 PM
Specified argument was out of the range of valid values. Parameter name: offset Here when i retrive image then the above error occurs...
Rajeev kumarPosted Oct 11, 2012, 9:08 PM
thanks for this articles..
Milan DuttaPosted Aug 4, 2012, 10:04 PM
Inserting And Reading Image To/From Database in ASP.NET (Web Application) in Image Control in here when i retrive image then one error come from Handler.ashx page,error is "ArgumentOutOfRangeException was unhandledby user code" Specified argument was out of the range of valid values. Parameter name: offset ...........................................what is this?????????
Vishal GilbilePosted Jul 17, 2012, 6:18 AM
you might have made a mistake in Handler file. check your handler file.
Siraj kPosted Jun 24, 2012, 10:13 AM
hello sir, i used ur coding as it is but for me image saving successfully but while retrieving it not shows image and other fields are working fine,,where i would be made mistake..... thanks...
surender bhyanPosted Aug 9, 2011, 3:48 AM
Keep posting sir
Rohatash KumarPosted Jul 19, 2011, 8:11 AM
I just looking for same....thanks a lot vishal.