Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET data reader for next loop

Posted on 2004-09-30
3
Medium Priority
?
239 Views
Last Modified: 2013-11-25
I'm very new to .NET, and playing with syntax that  I just can't get right.

I have a sql command that reads a number of records from my database.  In the table, there is a field called APPROVED.  When the user clicks a button, it reads the data.  If the field APPROVED has the value of HOLD, I want to exit the subroutine.  I was trying to put the value into a label, so I could test this out, and I can get it to read the last record fine.  I know I need a For / Next loop in the middle of this, but my brain must have gone because I can't get it right.  I've taken out all the things I tried, so you wouldn't wonder -- why that.

Here is the basic structure of the code:
        'select statement is above here
        dtrFinal = SqlSelectCostCenters.ExecuteReader()


        While dtrFinal.Read
             
            Label1.Text = (dtrFinal("Approved"))

            If Label1.Text = "HOLD" Then
                dtrFinal.Close()
                SqlConnection1.Close()
                Exit Sub
            Else
                'Label1.Text = "YOU ARE GOOD TO GO"
            End If

        End While
        SqlConnection1.Close()


How can I get it to exit the sub if it comes across a record with the word "HOLD" in the field called approved??

THANK YOU as always for any suggestions.
0
Comment
Question by:BetsyV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 2000 total points
ID: 12200136
BetsyV,
Possible the selected value is not returned as capital letter format? Others that, i cant see why it cant work.
eg:

While dtrFinal.Read
      If dtrFinal("Approved").ToString.ToUpper = "HOLD" Then
                Label1.Text = (dtrFinal("Approved"))
                dtrFinal.Close()
                SqlConnection1.Close()
                Exit Sub
      Else
                Label1.Text = "YOU ARE GOOD TO GO"
      End If
End While

0
 

Author Comment

by:BetsyV
ID: 12202477
Thank you for helping me think it through.  I always doubt my code.  It wasn't actually the upper/lower case, but I had to trim the data.  When I changed it to trim(dtrFinal("Approved").ToString.ToUpper) it worked like a charm.

THANKS !
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 12202658
Glad to help, BetsyV .

Regards
x_com
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question