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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:39:28+00:00 2026-06-14T19:39:28+00:00

Just wondering if someone can check my do while statement that is nested within

  • 0

Just wondering if someone can check my do while statement that is nested within an if/elseif statement to see where I’m potentially going wrong.

strSQL = "exec sp_CoursesStartingSoon"
    objConn = New SqlConnection(strConnection)
    objConn.Open()
    objCmd = New SqlCommand(strSQL, objConn)
    datareader = objCmd.ExecuteReader(0)
    datareader.Read()

If (datareader("subjectcode") = "F23") Then

        Do While (datareader("subjectcode") = "F23")

            html += "<h1>Access to HE</h1>"
            html += "<p>" & datareader("name") & "</p>"
            html += "<p>" & datareader("level") & "</p>"

        Loop

    ElseIf (datareader("subjectcode") = "F06") Then

        Do While (datareader("subjectcode") = "F06")

            html += "<h1>Art and Design</h1>"
            html += "<p>" & datareader("name") & "</p>"
            html += "<p>" & datareader("level") & "</p>"

        Loop


    End If

At the moment, the page isn’t loading and seems stuck in a loop but wanted to check if its my logic (which I’m assuming it is).

Thanks.

  • 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-06-14T19:39:29+00:00Added an answer on June 14, 2026 at 7:39 pm

    You are not progressing the datareader after the:

    Do While (datareader("subjectcode") = "F23")
    

    Therefore it is continuously reading the same record 🙂

    You need to put a:

    datareader.Read()
    

    in the loop somewhere.

    If you match any of the F23 or F06 checks, you will stay in the do while loop. Trust me.

    EDIT: here you go

        strSQL = "exec sp_CoursesStartingSoon"
        objConn = New SqlConnection(strConnection)
        objConn.Open()
        objCmd = New SqlCommand(strSQL, objConn)
        datareader = objCmd.ExecuteReader(0)
    
        While datareader.Read()
    
            If (datareader("subjectcode") = "F23") Then
    
                html += "<h1>Access to HE</h1>"
                html += "<p>" & datareader("name") & "</p>"
                html += "<p>" & datareader("level") & "</p>"
    
            ElseIf (datareader("subjectcode") = "F06") Then
    
                html += "<h1>Art and Design</h1>"
                html += "<p>" & datareader("name") & "</p>"
                html += "<p>" & datareader("level") & "</p>"
    
            End If
    
        End While
    

    Just to explain:

    To read the next record, you always need to do datareader.Read(). If there are no more records, the API will return false, and exit the loop correctly. You can then check the datareader cursor to see if the current record contains the strings you are looking for. Then when the code loops round again, the datareader.Read() will get the next record for you.

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

Sidebar

Related Questions

just wondering if someone can help me make this code work properly and be
Just wondering if someone can help me figure out why my menu is doing
Just wondering if someone could explain this to me? I have a program that
These are mainly just some things I've been wondering, maybe someone can give me
Just wondering if someone can help me understand why my regular expression is matching
Just wondering if someone can point me in the right direction. I want to
Just wondering if someone can help me out with this quickly. I have a
Just wondering if someone can assist me with the following issue. I have a
Just wondering if someone can assist me with the following issue. I have come
Just wondering if someone can help me code the following. I want to use

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.