Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table in database with name and image with binary data(image) i want to load the image on the basis of name given in text box

C#
string strQuery = "select img from exp where name='" + TextBox1.Text + "'";

this is fine in aspx but in image handler ashx file i want to pass the value of this textbox so that the same sql query can be applied

till now my handler file is

C#
using System;

using System.Web;

using System.Data.SqlClient;


 public class ShowImage : IHttpHandler
    { 

        public void ProcessRequest(HttpContext context)
        {

            string imageid = context.Request.QueryString["img"];


            SqlConnection con = new SqlConnection("server=.\\SQLEXPRESS;database=experiment;trusted_connection=true;");
            con.Open();
            SqlCommand command = new SqlCommand("select img from exp where (here i stuck....)", con);
            SqlDataReader dr = command.ExecuteReader();
            dr.Read();
            context.Response.BinaryWrite((Byte[])dr[0]);
            con.Close();
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
Posted
Updated 19-Oct-13 10:02am
v3

1 solution

C#
SqlCommand command = new SqlCommand("select img from exp where (here i stuck....)", con);


change this to ======>
C#
SqlCommand command = new SqlCommand("select img from exp where name='"+imageid+"'", con);


When you are calling this handler just pass the text box value in the querystring name "img" then everything should work fine.
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900