Image Loading from SQL Server into ASP.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have employee details stored in SQL DB includes emp id , name, age, sex
and photo (stored as image binary format).

Now in text box I am entering empid and click of a button I want to get all
the details into a aspx page

Name XXXXX
Age YY
Sex ZZ
Photo Photo should be displayed here

Please advise me how can I do this, all the other data I can populate but
how I will load employee photo. Photo should be displayed in the same page.

Thanks in advance
 
Hello,

You have two possiblities:

- Store the images in a folder of your website and store the link to
them in a field of your database (easy solution, and you don't have to fight
against performance problems storing blobs in your DB).

- You can phisically store it in your DB, take a look at this article:

http://www.ftponline.com/vsm/2002_07/online/hottips/esposito/

HTH
Braulio
/// ------------------------------
/// Braulio Díez
///
/// http://www.tipsdotnet.com
/// ------------------------------
 
Use Image handler to call a Image From database
call ur image in Image1 redirect it using querystring
call ur Image by a Primary Key into using ID;

Image1.ImageUrl =
"~/MyPhoto.ashx?Id=" + TextBox1.Text;

"MyPhoto.ashx" is a Image Handler

public class MyPhoto : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string id = context.Request.QueryString["Id"];
context.Response.ContentType =
"image/jpeg";
Stream strm = ShowEmpImage(id);
byte[] buffer = new byte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
}

public Stream ShowEmpImage(string id)
{
DataClassesDataContext context1 = new DataClassesDataContext();
var r = (from a in context1.ImageTables where a.Id == id select a).SingleOrDefault();
return new MemoryStream(r.FileSource.ToArray());
}
public bool IsReusable
{
get
{
return false;
}
}
}
 
Back
Top