can you explain what you want to do? I mean you want to show image on page or in image control. I want to show image in control then you have to go for HttpHandler Class.
Try following Code
Add HttpHandler Class
write this code
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Configuration;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string _productname;
if (context.Request.QueryString["_productname"] != null)
_productname=(context.Request.QueryString["_productname"]).ToString();
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/gif";
Stream strm = ShowEmpImage(_productname);
byte[] buffer = new byte[2525];
int byteSeq = strm.Read(buffer, 0, 2525);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 2525);
}
}
public Stream ShowEmpImage(string _productname)
{
string conn = ConfigurationManager.ConnectionStrings["sqlcn"].ConnectionString;
SqlConnection connection = new SqlConnection(conn);
string sql = "Ur Sp";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Product_Name", _productname);
connection.Open();
object img = cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])img);
}
catch
{
return null;
}
finally
{
connection.Close();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
write following code in aspx.cs file
Image imgload = new Image();
imgload.ImageUrl = "~/Handler.ashx?_productname=" + _productname;
if any clarification need feel free to ask