TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Santhonabin
NA
51
212.7k
image retrieve urgent
Nov 25 2010 5:44 AM
hi..
Anybody pls help me to recover this error..
ShowImage.ashx
----------------
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);
}
}
public
Stream
ShowEmpImage(
int
empno)
{
// string conn = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
// SqlConnection connection = new SqlConnection(conn);
// string sql = "SELECT empimg FROM empdetails1 WHERE empid = @ID";
// SqlCommand cmd = new SqlCommand(sql, connection);
// cmd.CommandType = CommandType.Text;
// cmd.Parameters.AddWithValue("@ID", empno);
SqlConnection
connection1 =
new
SqlConnection
(
"Data Source=RHINO;Initial Catalog=HR;password=hrproject;User ID=HR;"
);
connection1.Open();
SqlCommand
cmd =
new
SqlCommand
();
cmd.Connection = connection1;
cmd.CommandText =
"SELECT empimg FROM empdetails1 WHERE empid = '"
+ empno+
"'"
;
object
img = cmd.ExecuteScalar();
try
{
return
new
MemoryStream
((
byte
[])img);
}
catch
{
return
null
;
}
finally
{
connection1.Close();
}
}
public
bool
IsReusable
{
get
{
return
false
;
}
}
}
output:
images are not to be retrieved to image controls from DB ...
Attachment:
image website.rar
Reply
Answers (
1
)
Regarding Activex
retrieve selected row Gridview data and display on other page text boxes