我已完成将图像插入 Oracle 数据库。现在我正在尝试显示它。
我的处理程序代码是:
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();
}
}
我的 aspx 图像控件是:
<div>
This is the student image requested:
<asp:Image ID="picone" ImageUrl="~/Handler1.ashx?imgid=299" runat="server" />
</div>
当运行 aspx 时,我没有发现任何错误。但是图像没有显示。您可以在下面找到我得到的输出的屏幕截图。
我想知道出了什么问题。
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();
}
}
即使这样也行不通