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 7190717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:34:32+00:00 2026-05-28T19:34:32+00:00

Here is a summary of the behavior: while loop iterates to the end of

  • 0

Here is a summary of the behavior: while loop iterates to the end of the recordset, retrieves values. Values are then displayed in their respective places.

The issue is, I only want to display one set of values. Using while displays as many values as are records in the table being queried. Sample below:

What should display:

<div>
    <div>Service One is Stopped</div>
    <div>Service Two is Running</div>
    <div>Service Three is Stopped</div>
</div>

What actually happens:

<div>
    <div>Service One is </div> 
    <div>Service Two is Running</div>
    <div>Service Three is </div>
    <div>Service One is </div>
    <div>Service Two is </div>
    <div>Service Three is Running</div>
    <div>Service One is Stopped</div>
    <div>Service Two is </div>
    <div>Service Three is </div>
</div>

Below is the offending code. I apologize if this is a trivial question. I’m shaking off 2+ years of rust not writing code, and sometimes even the simple things get you :-). Many thanks for the assistance!!!

@using System.Configuration;
@using System.Data.SqlClient;
@using System.Data;
@using System.Linq;

@{
  System.Data.SqlClient.SqlConnection cn = null;
  cn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["sqlConn"].ToString());
  cn.Open();
  System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT DISTINCT * FROM servicehealth", cn);
  var myreader = cmd.ExecuteReader();
}
@{
int rowCount = 0;
}
@while (myreader.Read())
{
        rowCount++;
        string service1status = "";
        string service2status = "";
        string service3status = "";
        string servicename = @myreader["servicename"].ToString();

        switch (servicename.ToLower())
        {
            case "serviceone":
                service1status = @myreader["servicestate"].ToString();
                break;
            case "servicetwo":
                service2status = @myreader["servicestate"].ToString();
                break;
            case "service3":
                service3status = @myreader["servicestate"].ToString();
                break;
        }

<div>
    <div>Service One is @service1status</div>
    <div>Service Two is @service2status</div>
    <div>Service Three is @service3status</div>
</div>
}

EDIT: Here’s an abbreviated snapshot of the table in question:

ServiceId                   |  ServiceName  |   ServiceState  |  StartTrackTime  |  LastUpdated
1111-11111-111111-11111111  |  ServiceOne   |   Stopped       |  1/30/2012 0:00  |  1/30/2012 17:57
2222-22222-222222-22222222  |  ServiceTwo   |   Running       |  1/30/2012 0:00  |  1/30/2012 17:57
3333-33333-333333-33333333  |  ServiceThree |   Running       |  1/30/2012 0:00  |  1/30/2012 17:57
  • 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-28T19:34:33+00:00Added an answer on May 28, 2026 at 7:34 pm

    Looks like you could just output the service and it’s status during each iteration of the while and place it between the containing div tags. You should get one line for each service found.

    <div>
    @while (myreader.Read())
    {
         string servicestatus = servicestatus = @myreader["servicestate"].ToString();
         string servicename = @myreader["servicename"].ToString();
        <div>@servicename is @servicestatus</div>
    
    }
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a LINQ query going against an Entity Framework object. Here's a summary
Here is my implementation in summary 1) all DAOs implemented using HibernateDAO support/ @Transational
Here is my layout, Summary view http://img689.imageshack.us/img689/2500/yuidtsum.jpg I am using one div and many
Here's my problem: there's an internal issue tracking system that has a nice summary
Summary Hi All, OK, further into my adventures with custom controls... In summary, here
the summary here: $a = 213480.7-190.46; exit($a-213290.24); # 2.9103830456734E-11 the result output suppose to
I have the following structure: <div class=news> <p> summary here<a href=#>more</a> </p> <div class=more>
It has been a long question, so here is the summary first, I have
So I'm trying to build a async server... Here is a summary of what
I've been having the issue from here: Sharepoint issue, selective behavior? and I think

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.