?
Solved

VB.Net - DataReader Looping

Posted on 2013-01-28
3
Medium Priority
?
439 Views
Last Modified: 2013-01-29
Good Day Experts!

What is your preference to looping through a DataReader?  

I have seen:

While reader.Read()

End While

**************************

With reader
     .Read()
     Do While .HasRows

     Loop
End With

What are the pros/cons if any between the 2?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
[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
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 300 total points
ID: 38827179
I don't think there is any difference between the two approaches. Infact I suspect #2 will throw an error if there are no rows. I prefer the #1 approach.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 100 total points
ID: 38830185
CodeCruiser has it, there is not difference, but you should use the first set condition if you want to go the Loop route: Do While .Read().

There is something of a was between the proponents of the While and those who would rather use the Loop.

There is only one form of While...End While.

But there are 4 variations of the Do...Loop:
    Do While...Loop
    Do...Loop While
    Do Until...Loop
    Do...Loop Until

Those who prefer the Do...Loop argue that it gives you more control. I disagree with that. What I have seen in many years of code revision and debugging other programmers code is that those who use it often make mistakes. They think that they are in one form while they are in the other. This often end up missing one loop or doing one too many.

There is nothing that you can do with the Do...Loop that you cannot do with the While...End While. Just adjust the expression accordingly. But in my opinion, programmers who use the While...End While have only one way of seeing that kind of loop. They are used to it, and they do less mistakes.
0
 

Author Closing Comment

by:Jimbo99999
ID: 38831162
Thanks for the feedback as I continue my journey.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

765 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