Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4059500
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:13:01+00:00 2026-05-20T15:13:01+00:00

I cant figure out why when I try to output an image and a

  • 0

I cant figure out why when I try to output an image and a line of text below I only get the image what Am I doing wrong?

        SqlConnection cn = new SqlConnection("CONNECTIONINFO HERE");

        SqlCommand cmd = new SqlCommand("SELECT * FROM test WHERE id=" + Request.QueryString["id"], cn);

        cn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read()) //check to see if image was found
        {
            Response.ContentType = dr["fileType"].ToString();
            Response.BinaryWrite((byte[])dr["imagesmall"]);
            Response.Write("<br/>This is your image, if this is incorrect please contact the administrator.");
        }
        cn.Close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:13:02+00:00Added an answer on May 20, 2026 at 3:13 pm

    Create a HttpHandler for your images and call it from an image tag.

    like this:

    public class ImageHandler : IHttpHandler
    {
        public bool IsReusable 
        {
            get { return true; }
        }
    
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
    
            SqlConnection cn = new SqlConnection("CONNECTIONINFO HERE");
            SqlCommand cmd = new SqlCommand("SELECT * FROM test WHERE id=" + request.QueryString["id"], cn);
    
            cn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read()) //check to see if image was found
            {
                response.ContentType = dr["fileType"].ToString();
                response.BinaryWrite((byte[])dr["imagesmall"]);
            }
            cn.Close();
        }
    }
    

    Then use it like this:

    <img src="/ImageHandler.axd?id=1" />
    <p>This is your image, if this is incorrect please contact the administrator.</p>
    

    You will need to configure the handler in web.config or in IIS 7 if that is what you are using.

    Here is how: http://mvolo.com/blogs/serverside/archive/2007/08/15/Developing-IIS7-web-server-features-with-the-.NET-framework.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cant figure out how to get lua to do any common timing tricks,
I can't figure out what I'm doing wrong here. I have the following code:
I want to do something but cant figure out how to do this (i
I realize this perhaps a naive question but still I cant figure out how
i am trying to set the htmlAttribute property but i cant figure out the
I am getting segmentation fault in this code but i cant figure out why.
Maybe I missed something, but I cant figure out why Visual Studio 2008 isn't
I'm building a questionnaire mvc webapp, and i cant figure out how to pass
I cant figure out where I am messing up. I am passing an array
I can't figure it out.. Markup: <form> <fieldset><p> <label>Username: <input type=text name=user id=user /></label></p><br

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.