Click here to Skip to main content
11,490,003 members (69,450 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET
i tried below code
public void imagefetch()
    {
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        SqlConnection imagecon = new SqlConnection(onlineexam_Conn);
        string imagequery = "select rcimage,permitimage,pollutionimage,fitnessimage,taximage,insuranceimage from gps_vehicledetails where registration='" + vehicleSelect.SelectedItem.ToString() + "'";
        SqlDataAdapter da = new SqlDataAdapter(imagequery, imagecon);
        da.Fill(ds);
        dt = ds.Tables[0];
        showimages.DataSource = dt;
        showimages.DataBind();
        imagecon.Close();
    }

showimages is a grid control but i am unable to fetch image in grid. plese help me

public void ProcessRequestt(HttpContext context)
    {
        DataTable dt = new DataTable();
        SqlConnection connection = new SqlConnection(onlineexam_Conn);
        SqlCommand command = new SqlCommand("select rcimage,permitimage,pollutionimage,fitnessimage,taximage,insuranceimage from gps_vehicledetails where registration='AP 29 TA 1966'", connection);
        connection.Open();
        SqlDataReader dr = command.ExecuteReader();
        dr.Read();
        context.Response.BinaryWrite((Byte[])dr[0]);
        showimages.DataSource = dr;
        showimages.DataBind();
        connection.Close();
        context.Response.End();
    }  
in page load i am using image control property to retrieve image from database but i am unable to fetch image in image control. Please help me
Posted 17-Feb-13 19:58pm
Edited 17-Feb-13 20:04pm
v3
Comments
Karthik Harve at 18-Feb-13 1:05am
   
[Edit] added pre tags.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hi dear,
first of all device your code into 3 part.

1. design a grid
2. Bind Your Code
3. Implement IHttpHandler for image


1. Design
<asp:templatefield headertext="Photo" xmlns:asp="#unknown">
     <itemtemplate>
           <asp:image id="empImage" runat="server" imageurl="<%# "ImageHandler.ashx?ImID="+ Eval("ID") %>" width="100" height="120" alternatetext="Student Photo" descriptionurl="~/image/no-image-a.jpg" />
     </itemtemplate>
</asp:templatefield>


2. Bind Your Code
private void fillGrid(DataTable dt)
{
    myGrid.DataSource = dt;
    myGrid.DataBind()
       
}

3. Implement IHttpHandler for image
<%@ WebHandler Language="C#" Class="ImageHandler" %>
 
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
 
public class ImageHandler : IHttpHandler
{
 
    public void ProcessRequest(HttpContext context)
    {
        //context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
        string imageid = Convert.ToString(context.Request.QueryString["ImID"]);
        if (imageid != null && imageid.Trim() != "")
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ToString());
            connection.Open();
            SqlCommand command = new SqlCommand("select PHOTO from EmpMst where ID=" + imageid, connection);
            SqlDataReader dr = command.ExecuteReader();
            dr.Read();
            try
            {
                    context.Response.BinaryWrite((Byte[])dr[0]);
                    connection.Close();
                    //context.Response.End();
            }
            catch
            {
                Byte[] b = File.ReadAllBytes(context.Server.MapPath("~/image/no-image-a.jpg"));
                context.Response.BinaryWrite(b);
                connection.Close();
                context.Response.End();
            }
        }
        else
        {
            Byte[] b = File.ReadAllBytes(context.Server.MapPath("~/image/no-image-a.jpg"));
            context.Response.BinaryWrite(b);
        }
    }
 
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
 
}
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

more solutions pleassssseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 595
1 Andy Lanng 233
2 OriginalGriff 213
3 Maciej Los 170
4 _duDE_ 141
0 Sergey Alexandrovich Kryukov 9,608
1 OriginalGriff 8,475
2 Sascha Lefèvre 3,419
3 Maciej Los 3,106
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100