-1

I have some data stored in a Oracle database .. i would like to show the stored image data along with other data in a .asp page..

if i fetch data from the database and use header("Content-type: image/jpeg"); its not possible to show the image with other asp data.. is there a a other way ?

User
  • 1
  • 1
  • 6
  • possible duplicate of [What's the best way to display an image from a sql server database in asp.net?](http://stackoverflow.com/questions/612342/whats-the-best-way-to-display-an-image-from-a-sql-server-database-in-asp-net) – Al W Feb 20 '13 at 07:00

2 Answers2

0

Edit 1

here is a good link

http://www.codeproject.com/Articles/13365/Insert-retrieve-an-image-into-from-a-blob-field-in

Old

The below example is with SQL-Server
But you can change it according to Oracle

For oracle:-

 FileStream FS = new FileStream("image.jpg", FileMode.Create); 
 byte[] blob = (byte[])"YourValue"; 
 FS.Write(blob,0,blob.Length); 
 FS.Close(); 

Create a generic http handler as follows

using System;
using System.Configuration;
using System.Web;
using System.IO;
using System.Data;
using System.Data.SqlClient;

public class ShowImage : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
       Int32 empno;
       if (context.Request.QueryString["id"] != null)
          empno = Convert.ToInt32(context.Request.QueryString["id"]);
       else
          throw new ArgumentException("No parameter specified");

       context.Response.ContentType = "image/jpeg";
       Stream strm = ShowEmpImage(empno);
       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);
       }       
       //context.Response.BinaryWrite(buffer);
    }

    public Stream ShowEmpImage(int empno)
    {
         string conn = ConfigurationManager.ConnectionStrings     ["EmployeeConnString"].ConnectionString;
         SqlConnection connection = new SqlConnection(conn);
         string sql = "SELECT empimg FROM EmpDetails WHERE empid = @ID";
         SqlCommand cmd = new SqlCommand(sql,connection);
         cmd.CommandType = CommandType.Text;
         cmd.Parameters.AddWithValue("@ID", empno);
         connection.Open();
         object img = cmd.ExecuteScalar();
         try
        {
            return new MemoryStream((byte[])img);
        }
        catch
        {
            return null;
        }
        finally
       {
            connection.Close();
       }
    }

    public bool IsReusable
    {
        get
        {
             return false;
        }
    }


}

and display image as follow

 Image1.ImageUrl = "~/ShowImage.ashx?id=" + id;

There are some links below
Showing image in GridView from the database?
How to show a image in database in the image control of Asp.net?
Display image from database in ASP.net with C#
http://www.dotnetcurry.com/ShowArticle.aspx?ID=129

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
  • am try it.it's not working.how can i get a jpeg in the html,thanks. OracleConnection conn = new OracleConnectionConfigurationManager.AppSettings["ConnectionString6"]); OracleCommand cmd = conn.CreateCommand(); conn.Open(); cmd.CommandText = "SELECT TP FROM QCXX WHERE JH = '5G14-29'"; MemoryStream ms = new MemoryStream(); IDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { byte[] pic = (byte[])dr[0]; ms.Write(pic, 0, pic.Length); Response.ContentType = "image/jpeg"; Response.BinaryWrite(pic); Response.End(); } – User Feb 20 '13 at 07:01
-1

html tag

<img id="emp_photo" src="emp_photo.ashx?id=' + empId + '" title="' + 
                emName + '" alt="emp_photo" width="125px" height="170px"

emp_photo.ashx

Dim Query As String = "select fr.phote from follower_register fr where fr.follower=" &    context.Request.QueryString("id")
    db.Connect()
    Dim objConnection As OracleConnection = db.objConnection
    Dim ds As New DataSet
    Dim cmd As OracleCommand = New OracleCommand(Query, objConnection)
    Dim reader As OracleDataReader = cmd.ExecuteReader()
    If reader.Read() Then 
        context.Response.BinaryWrite(reader(0))
    End If
    db.Disconnect
शेखर
  • 17,412
  • 13
  • 61
  • 117
User
  • 1
  • 1
  • 6