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

  • SEARCH
  • Home
  • 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 5843977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:13:48+00:00 2026-05-22T12:13:48+00:00

This is in response to the question I asked earlier, since I can’t post

  • 0

This is in response to the question I asked earlier, since I can’t post it there before 8 hours, I’ve created a new question, with the problem I’m facing,

Here’s the code:

if (context.Request.QueryString["id"] != null)
{
       int id = int.Parse(context.Request.QueryString["id"].ToString());
       string connectionString = "Data Source=tarun-PC\\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=True";
       string commandString = "Select fsImage from WHATSNSTORE_FEATURED_STORES where imageId=" + id;

       SqlConnection oConnection = new SqlConnection(connectionString);
       SqlCommand oCommand = new SqlCommand(commandString, oConnection);

       if (oConnection.State != ConnectionState.Open)
       {
            oConnection.Open();
       }

       SqlDataReader myDataReader = oCommand.ExecuteReader();

      //myDataReader.Read();

       try
       {
            if (myDataReader.Read())
            {
                 context.Response.ContentType = "image/jpg";
                 context.Response.BinaryWrite((byte[])myDataReader["fsImage"]);
            }
       }
       catch (Exception ex)
       {

         context.Response.Write(ex.Message);
       }

My Table

create table WHATSNSTORE_FEATURED_STORES
(
    imageId int primary key identity,
    fsImage image
)

The only problem now is, while debugging it skips the if(myDataReader.Read()) part, which indicates that there is no data present !

How do I solve the issue?

  • 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-22T12:13:49+00:00Added an answer on May 22, 2026 at 12:13 pm

    If your reader is empty it means your query did not return a result.

    Looking at your code i’d say the image is missing from the database. You should probably assume that that can and will happen and either stream a blank image to the browser or return a HTTP 404 error.

    [Update]

    Did you check the generated SQL string? When you add the id to the SQL string it is cast back to a string. If the id is over 1000 you may get a localized representation of the integer (ie. 1.000 instead of 1000). That would explain why your query in SSMS does return a result while the page does not.

    Original answer:
    I noticed you are using int.Parse; you may want to use int.TryParse instead. That will just return false if the value is not a valid int.
    Additionally, you’re building your SQL by string concatenation. This is considered a bad practice. You should use parameters.
    Another best practice is to wrap the connection and the reader in a using statement. That will ensure the connection and reader are closed when they are no longer needed, especially in case of an exception.
    Finally, you may want to consider moving the connection string to your web.config file.

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

Sidebar

Related Questions

Ok, so this question has been asked before here . In the response/answer to
Danny initially asked this question in response to a recent Scott Hanselman post: Who
Hi I know this question have been asked before but the answers there isn't
I had asked this question on Javaranch , but couldn't get a response there.
I asked a related but very general question earlier (see especially this response ).
I've asked this question on the Awesomium forms but I haven't received any response
I asked this question on superuser , but haven't gotten a response. Maybe here
I originally asked this question on RefactorMyCode , but got no responses there... Basically
I know this question has been asked many times, but my problem is a
I asked a similar question before, but got no helpful response so I will

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.