I have accomplished inserting an image into the Oracle database. Now I am trying to display it.
My handler code is :
public void ProcessRequest(HttpContext context)
{
OracleDataReader dr = null;
OracleCommand cmd = null;
OracleConnection conn = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVER_NAME=XE)));User Id=sakthi_studdb;Password=sakthi;");
try
{
cmd = new OracleCommand
("select IMAGE from IMAGETBL where ID=" +
context.Request.QueryString["imgid"], conn);
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
context.Response.ContentType = "image/jpg";
context.Response.BinaryWrite((byte[])dr["IMAGE"]);
}
if (dr != null)
dr.Close();
}
finally
{
if (conn != null)
conn.Close();
}
}
And my aspx image control is :
<div>
This is the student image requested:
<asp:Image ID="picone" ImageUrl="~/Handler1.ashx?imgid=299" runat="server" />
</div>
When the run the aspx, I don't find any errors. But the image is not displaying. You can find the screen shot of the output I get below.
I want to know what is wrong.
public void ProcessRequest(HttpContext context)
{
OracleConnection conn = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVER_NAME=XE)));User Id=sakthi_studdb;Password=sakthi;");
try
{
long imageId = Convert.ToInt64(context.Request.QueryString["imgid"]);
using (OracleCommand cmd = new OracleCommand("select IMAGE from IMAGETBL where ID=:ID", conn))
{
cmd.Parameters.Add(":ID", OracleDbType.Int64).Value = imageId;
conn.Open();
context.Response.ContentType = "image/gif";
context.Response.BinaryWrite((byte[])cmd.ExecuteScalar());
}
}
finally
{
if (conn != null)
conn.Close();
}
}
Even this din't work