Click here to Skip to main content
14,769,975 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hello i am facing one problem,,,

Retrieve Image from Database , its show only icon of image but not image.

Coding as follows
In UI Code
Image1.ImageUrl = "HandlerLogo.ashx?company_id=" + comp_id;

In Handler,Coding

MemoryStream memoryStream = new MemoryStream();
SqlConnection connection = new SqlConnection(GetConnectionString());
string sql = "select company_logo from Recruiter_RegisterLogin where company_id=@company_id";

SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@company_id", id);

SqlDataReader reader = cmd.ExecuteReader();

byte[] file = (byte[])reader["company_logo"];

memoryStream.Write(file, 0, file.Length);
context.Response.Buffer = true;
Updated 1-Apr-13 9:30am
There is no such thing as "icon of image". Do you mean reduced copy, some kind of thumbnail version? But if this is something you store in a database, how anyone can help you?
Store the full-size images, of file names...
Prasad Khandekar 1-Apr-13 14:34pm
Hello Inderveer,

You may find this article useful. ( Especially the reading part. The reader(col_name) syntax typically won't work large data size.

1 solution

See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]

If you didn't insert it correctly, then it won't display either.

If that doesn't help, try this: A generic Image-From-DB class for ASP.NET[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900