I've been struggling for a couple of weeks with this project and I havnt made any real progress.
I have a table in an oracle database that contains employee photos (jpegs) in blob columns. From all my research it appears that what i need to use is an httphandler file to display these photos on a web page. I have tried modifying every example I have found and just can't get anything to work. I think part of my problem is that I dont know enough about asp.net to translate between the examples which are always sqlserver centric and oracle, and this is my first asp.net project so I am at a loss at this point.
I can put a gridview control on my page and display my records except that the blob column shows up in the grid as "System.Byte []"
From what I have found so far I think I need a call in my gridview columns to an httphandler to return the actual images. I've found several examples of code that are supposed to do this but I have not been able to make any of them work.
My table is something like: emp_id, emplname, empfname, emp_photo so my gridview is basically a "select * from employees."
From what i can find, I need to add a column to the grid that contains something like
<asp:imageField="imImage.ImageUrl = "~/ImageHandler.ashx?ImID=emp_id; emp_photo" HeaderText="photo" SortExpression="photo">
</asp:imagefield>
and the imagehandler.ashx file would contain something like:
<%@ WebHandler Language="C#" Class="ImageHandler" %>
using System;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
public class ImageHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string imageid = context.Request.QueryString["ImID"];
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings
["connectionString"].ConnectionString);
connection.Open();
SqlCommand command = new SqlCommand("select photo from employees where emp_id="+imageid, connection);
SqlDataReader dr = command.ExecuteReader();
dr.Read();
context.Response.BinaryWrite((Byte[])dr[0]);
connection.Close();
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
This example seems simpler than most of the examples I have found, but I have not had any luck modifying it to make it work.
Can anybody point me to any examples that are simple enough that I might be able to make some progress?
thanks in advance for any help or suggestions
I have a table in an oracle database that contains employee photos (jpegs) in blob columns. From all my research it appears that what i need to use is an httphandler file to display these photos on a web page. I have tried modifying every example I have found and just can't get anything to work. I think part of my problem is that I dont know enough about asp.net to translate between the examples which are always sqlserver centric and oracle, and this is my first asp.net project so I am at a loss at this point.
I can put a gridview control on my page and display my records except that the blob column shows up in the grid as "System.Byte []"
From what I have found so far I think I need a call in my gridview columns to an httphandler to return the actual images. I've found several examples of code that are supposed to do this but I have not been able to make any of them work.
My table is something like: emp_id, emplname, empfname, emp_photo so my gridview is basically a "select * from employees."
From what i can find, I need to add a column to the grid that contains something like
<asp:imageField="imImage.ImageUrl = "~/ImageHandler.ashx?ImID=emp_id; emp_photo" HeaderText="photo" SortExpression="photo">
</asp:imagefield>
and the imagehandler.ashx file would contain something like:
<%@ WebHandler Language="C#" Class="ImageHandler" %>
using System;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
public class ImageHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string imageid = context.Request.QueryString["ImID"];
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings
["connectionString"].ConnectionString);
connection.Open();
SqlCommand command = new SqlCommand("select photo from employees where emp_id="+imageid, connection);
SqlDataReader dr = command.ExecuteReader();
dr.Read();
context.Response.BinaryWrite((Byte[])dr[0]);
connection.Close();
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
This example seems simpler than most of the examples I have found, but I have not had any luck modifying it to make it work.
Can anybody point me to any examples that are simple enough that I might be able to make some progress?
thanks in advance for any help or suggestions